hrw_hash/
hasher.rs

1use {
2    rapidhash::RapidHasher,
3    std::hash::{Hash, Hasher},
4};
5
6/// Hasher used to hash both nodes and keys.
7pub trait NodeHasher {
8    fn hash<K: Hash>(&self, key: &K) -> u64;
9}
10
11/// Default hasher used in the library.
12pub struct DefaultNodeHasher;
13
14impl NodeHasher for DefaultNodeHasher {
15    fn hash<K: Hash>(&self, key: &K) -> u64 {
16        let mut hasher = RapidHasher::default();
17        key.hash(&mut hasher);
18        hasher.finish()
19    }
20}
21
22#[inline]
23pub(crate) fn merge(a: &u64, b: &u64) -> u64 {
24    let mut distance = *a ^ *b;
25    distance ^= distance >> 33;
26    distance = distance.wrapping_mul(0xff51_afd7_ed55_8ccd);
27    distance ^= distance >> 33;
28    distance = distance.wrapping_mul(0xc4ce_b9fe_1a85_ec53);
29    distance ^= distance >> 33;
30    distance
31}
32