6.31. kink/container/HASH_SET

Provides a `set` implementation which stores elements in a hash table.

If elements 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 element extension by crypto-random data.

6.31.1. HASH_SET.new($hash ...[$config={}])

`new` returns a new empty hash `set`.

Config method

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

Equivalence relation

$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 elements.

Hash

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

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

Preconditions

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

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

Example

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

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

:Set <- HASH_SET.new(VAL$id_hash){(:C)
  C.eq(VAL$same?)
}
Set.push(X)
Set.push(Y)
stdout.print_line(Set.have?(X).repr)  # => true
stdout.print_line(Set.have?(Z).repr)  # => false