precomputed_map/
phf.rs

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