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($eq?): default = {(:X :Y) X == Y }

Equivalence of keys

$eq? is used to compare keys. $eq? must be an equivalence relation which satisfies the following for all X, Y, and Z in the domain of keys.

• reflexive: eq?(X X)

• symmetric: (if eq?(X Y) then eq?(Y X)) and (if not eq?(X Y) then not eq?(Y X))

• transitive: if eq?(X Y) and eq?(Y Z) then eq?(X Z)

Hash

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

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

Preconditions

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

$eq? 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"