hash32/fnv.rs
1const BASIS: u32 = 0x811c9dc5;
2const PRIME: u32 = 0x1000193;
3
4/// 32-bit Fowler-Noll-Vo hasher
5pub struct Hasher {
6 state: u32,
7}
8
9impl Default for Hasher {
10 fn default() -> Self {
11 Hasher { state: BASIS }
12 }
13}
14
15impl ::Hasher for Hasher {
16 #[inline]
17 fn finish(&self) -> u32 {
18 self.state
19 }
20
21 #[inline]
22 fn write(&mut self, bytes: &[u8]) {
23 for byte in bytes {
24 self.state ^= u32::from(*byte);
25 self.state = self.state.wrapping_mul(PRIME);
26 }
27 }
28}