pub const TREE_SEED_LITERAL: &str = "DEADBEEF_BANANA";
pub const TREE_SEED: u64 = fnv1a_64(TREE_SEED_LITERAL.as_bytes());
pub const fn fnv1a_64(bytes: &[u8]) -> u64 {
const FNV_OFFSET: u64 = 0xcbf2_9ce4_8422_2325;
const FNV_PRIME: u64 = 0x0000_0100_0000_01b3;
let mut hash = FNV_OFFSET;
let mut i = 0;
while i < bytes.len() {
hash ^= bytes[i] as u64;
hash = hash.wrapping_mul(FNV_PRIME);
i += 1;
}
hash
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn seed_is_deterministic_and_nonzero() {
assert_eq!(TREE_SEED, fnv1a_64(b"DEADBEEF_BANANA"));
assert_ne!(TREE_SEED, 0);
}
#[test]
fn fnv1a_matches_known_vector() {
assert_eq!(fnv1a_64(b""), 0xcbf2_9ce4_8422_2325);
assert_eq!(fnv1a_64(b"a"), 0xaf63_dc4c_8601_ec8c);
assert_eq!(fnv1a_64(b"foobar"), 0x8594_4171_f739_67e8);
}
}