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
| Name | Type | Notes |
|---|---|---|
bytes | *(u8) | |
length | usize |
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
| Name | Type | Notes |
|---|---|---|
hash | u64 | |
other | u64 |
Returns: u64
Constants
FNV offset basis constant (0xcbf29ce484222325).
Value: 14695981039346656037
FNV prime constant (0x100000001b3).
Value: 1099511628211