6.30. kink/container/HASH_MAP

Provides a `map` implementation which stores keys in a hash table.

If keys can be passed from the public, ensure that the distribution of the hash is not predictable, in order to prevent DDoS attacks. You might need to use a cryptograghic hash function and perform key extension by crypto-random data.

6.30.1. HASH_MAP.new($hash ...[$config={}])

`new` returns a new empty hash `map`.

Config method:

• C.eq($equivalent_to?): default = {(:X :Y) X == Y }

Equivalence relation of keys

$equivalent_to? must be a function which takes two args X and Y. `equivalent_to?(X Y)` must return the bool value of `X equivalent-to Y`, where `equivalent-to` is the equivalence relation of keys.

Hash

$hash must satisfy the following for all X and Y in the domain of keys.

• if equivalent_to?(X Y) then hash(X) == hash(Y)

Preconditions

$hash must be a fun which takes a key, and returns an integer `num`.

$equivalent_to? must be a fun which takes two keys, and returns a `bool`.

Example

:HASH_MAP.require_from('kink/container/')
:VAL.require_from('kink/')

:X <- new_val
:Y <- new_val
:Z <- new_val

:Map <- HASH_MAP.new(VAL$id_hash){(:C)
  C.eq(VAL$same?)
}
Map.set(X 'x')
Map.set(Y 'y')
Map.set(Z 'z')
stdout.print_line(Map.get(X).repr)  # => "x"