pub fn fnv1a_32(data: &[u8]) -> u32Expand description
Computes the FNV-1a hash (32-bit) of the provided data.
FNV-1a is an improved variant of the original FNV-1 algorithm with better dispersion properties. It is generally considered superior to FNV-1 for most use cases.
§Algorithm
FNV-1a works by:
- Starting with an initial basis value (2166136261 for 32-bit FNV-1a)
- For each byte in the input: a. XOR the current hash with the current byte b. Multiply the result by the FNV prime (16777619 for 32-bit)
The key difference from FNV-1 is the order of operations (XOR then multiply, vs multiply then XOR).
§Parameters
data- A slice of bytes to hash
§Returns
A 32-bit unsigned integer representing the hash value
§Example
use simplehash::fnv1a_32;
let data = b"hello world";
let hash = fnv1a_32(data);
println!("FNV1a-32 hash: 0x{:08x}", hash);