HashMap
Mutable hash map (aka Hashtable)
This module defines an imperative hash map (hash table), with a general key and value type.
It has a minimal object-oriented interface: get
, set
, delete
, count
and entries
.
The class is parameterized by the key’s equality and hash functions,
and an initial capacity. However, as with the Buffer
class, no array allocation
happens until the first set
.
Internally, table growth policy is very simple, for now: Double the current capacity when the expected bucket list size grows beyond a certain constant.
HashMap
class HashMap<K, V>(initCapacity : Nat, keyEq : (K, K) -> Bool, keyHash : K -> Hash.Hash)
An imperative HashMap with a minimal object-oriented interface.
Maps keys of type K
to values of type V
.
delete
func delete(k : K)
Deletes the entry with the key k
. Doesn’t do anything if the key doesn’t
exist.
remove
func remove(k : K) : ?V
Removes the entry with the key k
and returns the associated value if it
existed or null
otherwise.
get
func get(k : K) : ?V
Gets the entry with the key k
and returns its associated value if it
existed or null
otherwise.
replace
func replace(k : K, v : V) : ?V
Insert the value v
at key k
and returns the previous value stored at
k
or null
if it didn’t exist.
entries
func entries() : Iter.Iter<(K, V)>
Returns an iterator over the key value pairs in this
HashMap
. Does not modify the HashMap
.