Skip to main content

testx/
hash.rs

1use std::hash::Hasher;
2
3/// Deterministic hasher (FNV-1a) that produces identical output across Rust versions.
4/// `DefaultHasher` is explicitly documented as non-portable across compiler versions.
5pub struct StableHasher(u64);
6
7impl StableHasher {
8    pub fn new() -> Self {
9        Self(0xcbf29ce484222325) // FNV offset basis
10    }
11}
12
13impl Default for StableHasher {
14    fn default() -> Self {
15        Self::new()
16    }
17}
18
19impl Hasher for StableHasher {
20    fn finish(&self) -> u64 {
21        self.0
22    }
23
24    fn write(&mut self, bytes: &[u8]) {
25        for &byte in bytes {
26            self.0 ^= byte as u64;
27            self.0 = self.0.wrapping_mul(0x100000001b3); // FNV prime
28        }
29    }
30}