Skip to content
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 hashmap h.
  • (hashmap-empty? h) returns true if the hashmap h 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 with key in hashmap h or panics if the key is not present.
  • (hashmap-get-or h key not-found) works as hashmap-get, but calls not-found with no argument when it fails.
  • (hashmap-contains? h key) returns true if hashmap h contains key.
  • (hashmap-set! h key value) sets the value associated with key to value in hashmap h. If the key is already present, the original value is replaced.
  • (hashmap-remove! h key) removes the key from hashmap h 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.