stable_bloom_filter/
fnv.rs1use std::hash::Hasher;
2
3#[derive(Clone)]
4pub struct FnvHasher(u64);
5
6impl Default for FnvHasher {
7 #[inline]
8 fn default() -> FnvHasher {
9 FnvHasher(0xcbf2_9ce4_8422_2325)
10 }
11}
12
13impl FnvHasher {
14 #[inline]
17 pub fn with_key(key: u64) -> FnvHasher {
18 FnvHasher(key)
19 }
20}
21
22impl Hasher for FnvHasher {
23 #[inline]
24 fn finish(&self) -> u64 {
25 self.0
26 }
27
28 #[inline]
29 fn write(&mut self, bytes: &[u8]) {
30 let FnvHasher(mut hash) = *self;
31
32 for byte in bytes.iter() {
33 hash ^= u64::from(*byte);
34 hash = hash.wrapping_mul(0x0100_0000_01b3);
35 }
36
37 *self = FnvHasher(hash);
38 }
39}