HashMap<K, V>

Hash-based key-value store with O(1) average lookup.

Type Constraints: K Constrains Hashable, V Constrains None

xxml
Language::Collections

Methods

MethodParametersReturnsDescription
ConstructorHashMap<K,V>^Create empty map
putkey: K^, value: V^NoneInsert or update
getkey: K^V^Get value by key
removekey: K^Bool^Remove key-value pair
containsKeykey: K^Bool^Check if key exists
sizeInteger^Number of pairs
isEmptyBool^Check if empty
clearNoneRemove all pairs
keysList<K>^Get all keys
valuesList<V>^Get all values
beginHashMapIterator<K,V>^Get iterator

Examples

HashMap Usage

xxml
Instantiate Collections::HashMap<String, Integer>^ As <ages> =
    Collections::HashMap@String, Integer::Constructor();

Run ages.put(String::Constructor("Alice"), Integer::Constructor(30));
Run ages.put(String::Constructor("Bob"), Integer::Constructor(25));

Instantiate Integer^ As <aliceAge> = ages.get(String::Constructor("Alice"));  // 30

See Also