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
8// private in the next version
9#[doc(hidden)]
10pub fn hash_pilot(k: u64, pilot: u8) -> u64 {
11    const C: u64 = 0x517cc1b727220a95;
12
13    // fxhash
14    C.wrapping_mul(k ^ u64::from(pilot))
15}
16
17#[derive(Default)]
18pub struct U64Hasher<H: Hasher + Default>(PhantomData<H>);
19
20impl<H: Hasher + Default> HashOne for U64Hasher<H> {
21    fn hash_one<T: Hash>(k: u64, v: T) -> u64 {
22        let mut h = H::default();
23        h.write_u64(k);
24        v.hash(&mut h);
25        h.finish()
26    }
27}