Hash

GitHub   Edit on GitHub

Utilities for hashing any value.

Added in 0.1.0 No other changes yet.
1
from "hash" include Hash
1
2
let hashInstance = Hash.make()
assert Hash.hash(hashInstance, "Hello World") == Hash.hash(hashInstance, "Hello World")
1
2
let hashInstance = Hash.makeSeeded(10)
assert Hash.hash(hashInstance, "Hello World") == Hash.hash(hashInstance, "Hello World")

Types

Type declarations included in the Hash module.

Hash.HashInstance

Added in 0.7.0 No other changes yet.
1
type HashInstance

Represents a particular hashing instance.


Values

Functions and constants included in the Hash module.

Hash.make

Added in 0.7.0 No other changes yet.
1
make: () => HashInstance

Produces a generic hash instance using a random seed value.

Returns:

type description
HashInstance A hashing instance that can be consumed during hashing

Throws:

Failure(String)

  • If WASI random_get fails

Examples:

1
2
let hashInstance = Hash.make()
assert Hash.hash(hashInstance," Hello World") == Hash.hash(hashInstance, "Hello World)

Hash.makeSeeded

Added in 0.7.0 No other changes yet.
1
makeSeeded: (seed: Number) => HashInstance

Produces a hashInstance using the given seed.

Parameters:

param type description
seed Number The seed to use while hashing

Returns:

type description
HashInstance A hashing instance that can be consumed during hashing

Examples:

1
2
let hashInstance = Hash.makeSeeded(1)
assert Hash.hash(hashInstance," Hello World") == Hash.hash(hashInstance, "Hello World)
1
2
3
let hashInstance1 = Hash.makeSeeded(1)
let hashInstance2 = Hash.makeSeeded(2)
assert Hash.hash(hashInstance1," Hello World") != Hash.hash(hashInstance2, "Hello World)

Hash.hash

Added in 0.1.0
versionchanges
0.7.0Added `hashInstance` parameter instead of using a global seed
1
hash: (hashInstance: HashInstance, anything: a) => Number

A generic hash function that produces an integer from any value given a hashing instance. If a == b then Hash.hash(h, a) == Hash.hash(h, b).

Parameters:

param type description
hashInstance HashInstance The hashing instance to use as a seed
anything a The value to hash

Returns:

type description
Number A hash for the given value

Examples:

1
2
let hashInstance = Hash.makeSeeded(1)
assert Hash.hash(hashInstance," Hello World") == Hash.hash(hashInstance, "Hello World)
This is a notification!