| 1 | use crate::Hasher as _; |
| 2 | |
| 3 | const BASIS: u32 = 0x811c9dc5; |
| 4 | const PRIME: u32 = 0x1000193; |
| 5 | |
| 6 | /// 32-bit Fowler-Noll-Vo hasher |
| 7 | pub struct Hasher { |
| 8 | state: u32, |
| 9 | } |
| 10 | |
| 11 | impl Default for Hasher { |
| 12 | fn default() -> Self { |
| 13 | Hasher { state: BASIS } |
| 14 | } |
| 15 | } |
| 16 | |
| 17 | impl crate::Hasher for Hasher { |
| 18 | #[inline ] |
| 19 | fn finish32(&self) -> u32 { |
| 20 | self.state |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | impl core::hash::Hasher for Hasher { |
| 25 | #[inline ] |
| 26 | fn write(&mut self, bytes: &[u8]) { |
| 27 | for byte: &u8 in bytes { |
| 28 | self.state ^= u32::from(*byte); |
| 29 | self.state = self.state.wrapping_mul(PRIME); |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | #[inline ] |
| 34 | fn finish(&self) -> u64 { |
| 35 | self.finish32().into() |
| 36 | } |
| 37 | } |
| 38 | |