Module alg/hash

alg/hash

FNV-1a (Fowler-Noll-Vo) hash function.

A fast, non-cryptographic hash function with good distribution. Used internally by HashMap and HashSet.

Functions

fnv1a_hash_bytes function
fn(bytes : *(u8), length : usize) -> u64

Hash a byte sequence using FNV-1a.

Parameters

NameTypeNotes
bytes*(u8)
lengthusize

Returns: u64

hash_combine function
fn(hash : u64, other : u64) -> u64

Combine two hash values using hash * 31 + other.

The constant 31 is chosen because it is prime, close to a power of 2 (fast multiplication), and proven effective in practice.

Parameters

NameTypeNotes
hashu64
otheru64

Returns: u64

Constants

FNV_OFFSET_BASIS constant u64

FNV offset basis constant (0xcbf29ce484222325).

Value: 14695981039346656037

FNV_PRIME constant u64

FNV prime constant (0x100000001b3).

Value: 1099511628211