globset/
fnv.rs

1/// A convenience alias for creating a hash map with an FNV hasher.
2pub(crate) type HashMap<K, V> =
3    std::collections::HashMap<K, V, std::hash::BuildHasherDefault<Hasher>>;
4
5/// A hasher that implements the Fowler–Noll–Vo (FNV) hash.
6pub(crate) struct Hasher(u64);
7
8impl Hasher {
9    const OFFSET_BASIS: u64 = 0xcbf29ce484222325;
10    const PRIME: u64 = 0x100000001b3;
11}
12
13impl Default for Hasher {
14    fn default() -> Hasher {
15        Hasher(Hasher::OFFSET_BASIS)
16    }
17}
18
19impl std::hash::Hasher for Hasher {
20    fn finish(&self) -> u64 {
21        self.0
22    }
23
24    fn write(&mut self, bytes: &[u8]) {
25        for &byte in bytes.iter() {
26            self.0 = self.0 ^ u64::from(byte);
27            self.0 = self.0.wrapping_mul(Hasher::PRIME);
28        }
29    }
30}