A 32-bit hash of size bytes at data. Pass the previous result as h to hash several pieces as one.
#import "Hash";
Hash functions for strings, bytes and scalars: get_hash for general use, fnv1a_hash and sdbm_hash for bytes, djb2_hash for strings.
The functions are fast and well spread, not secure: don't use them for passwords or to guard against crafted input.
assert(get_hash("jacket") == get_hash("jacket"));
assert(get_hash(1) != get_hash(2));Procedures#
(data: *void, size: int, h := HASH_INIT) -> u32
(f: *float, count: int, h := HASH_INIT) -> u32
A 32-bit hash of count floats starting at f. Negative zero hashes like zero.
values := float.[1.5, 2.5];
assert(sdbm_float_hash(values.data, 2) == sdbm_float_hash(values.data, 2));↗(s: string) -> u32
A 32-bit hash of a string.
(val: u64, h := FNV_64_OFFSET_BIAS) -> u64
(data: *void, size: int, h := FNV_64_OFFSET_BIAS) -> u64
One step of 64-bit FNV-1a: mixes val into the hash h.
h := fnv1a_hash(1);
assert(h != fnv1a_hash(2));
assert(fnv1a_hash(2, h) != h);↗(x: u64) -> u64
Scrambles an integer by multiplying it with a large odd constant. The high bits of the result are the well mixed ones.
assert(knuth_hash(1) != knuth_hash(2));↗(s: string, h := HASH_INIT) -> u32
(array: [] $T, h := HASH_INIT) -> u32
(x: $T, h := HASH_INIT) -> u32
A 32-bit hash of a string. This is the hash Table uses for string keys.
Constants#
:: 0x100000001b3
The 64-bit FNV prime and offset basis that fnv1a_hash starts from.
:: 0xcbf29ce484222325
The starting value of a 64-bit FNV-1a hash.