precomputed_map/
phf.rs

1use core::hash::{ Hash, Hasher };
2use core::marker::PhantomData;
3
4pub trait HashOne {
5    fn hash_one<T: Hash>(k: u64, v: T) -> u64;
6}
7
8pub fn hash_pilot(k: u64, pilot: u8) -> u64 {
9    const C: u64 = 0x517cc1b727220a95;
10
11    // fxhash
12    C.wrapping_mul(k ^ u64::from(pilot))
13}
14
15#[derive(Default)]
16pub struct U64Hasher<H: Hasher + Default>(PhantomData<H>);
17
18impl<H: Hasher + Default> HashOne for U64Hasher<H> {
19    fn hash_one<T: Hash>(k: u64, v: T) -> u64 {
20        let mut h = H::default();
21        h.write_u64(k);
22        v.hash(&mut h);
23        h.finish()
24    }
25}