-
Notifications
You must be signed in to change notification settings - Fork 0
module std.hashmap
Jan Špaček edited this page Apr 12, 2016
·
1 revision
Hashmaps (or hash tables) are mutable associative containers based on hashing. To create a hashmap, one needs to provide a hasher, which maps keys to integers. When two keys are equal, their hashes also must be equal. See module std.hash for some convenient hash functions.
-
(hashmap-new hasher equal)
creates a new hashmap.hasher
must be a function of one argument that maps keys to their hashes.equal
must be a function of two arguments that is used to compare keys for equality. -
(hashmap-len h)
returns the number of elements in hashmaph
. -
(hashmap-empty? h)
returns true if the hashmaph
contains no elements. -
(hashmap-max-load h)
returns the maximum load factor of the hash map (it will rehash itself then the load is exceeded). -
(hashmap-set-max-load! h load)
sets the maximum load factor (must be number greater than 0 and not greater than 1, it is 0.8 by default). -
(hashmap-get h key)
returns the value associated withkey
in hashmaph
or panics if the key is not present. -
(hashmap-get-or h key not-found)
works ashashmap-get
, but callsnot-found
with no argument when it fails. -
(hashmap-contains? h key)
returns true if hashmaph
containskey
. -
(hashmap-set! h key value)
sets the value associated withkey
tovalue
in hashmaph
. If the key is already present, the original value is replaced. -
(hashmap-remove! h key)
removes thekey
from hashmaph
if it is present and does nothing if it is not. -
(hashmap-to-list h)
returns a list of key-value cons cells in an arbitrary order.