6.4. kink/BIN_HASHER

6.4.1. type bin_hasher

`bin_hasher` is, conceptually, an immutable tuple of (Hash_algorithm, Accumulated_bin). When `Tail_bin` is given to `hash` method, it calculates a hash value of (Accumulated_bin + Tail_bin) by `Hash_algorithm`.

There is no method to return `Accumulated_bin` itself. Thus, implementations are allowed to hold the compressed state calculated from `Accumulated_bin`, instead of `Accumulated_bin` itself.

Example

6.4.1.1. Hasher.hash(...[Tail_bin=BIN.of()])

`hash` calculates a hash value from (Accumulated_bin + Tail_bin), then return it as a `bin`.

Precondition

`Tail_bin` must be a `bin`

6.4.1.2. Hasher + Bin

`+` operator, or `op_add` method, returns a new `bin_hasher` of (Hash_algorithm, Accumulated_bin + Bin).

Precondition

`Bin` must be a `bin`.

6.4.2. BIN_HASHER.for(Hash_algorithm ...[$config={}])

`for` makes a `bin_hasher` of (Hash_algorithm, BIN.of()).

Config methods:

• C.on_success($success): default = VAL.identity

• C.on_error($error): default = a fun which raises an exception

If a `bin_hasher` is created, `for` tail-calls $success with the `bin_hasher`.

If `Hash_algorithm` is not supported, `for` tail-calls $error with no arg.

Precondition

`Hash_algorithm` must be a `str`.

$success must be a function which takes a `bin_hasher`.

$error must be a thunk.

6.4.3. BIN_HASHER.is?(Val)

`is?` returns whether `Val` is a `bin_hasher`.