Skip to main content

luaur_common/records/
pair_hash.rs

1use crate::functions::hash_combine::hash_combine;
2
3#[allow(non_snake_case)]
4#[derive(Debug, Clone, Default)]
5pub struct PairHash<T1, T2, H1, H2> {
6    pub(crate) h1: H1,
7    pub(crate) h2: H2,
8    pub(crate) _marker: core::marker::PhantomData<(T1, T2)>,
9}
10
11impl<T1, T2, H1, H2> PairHash<T1, T2, H1, H2>
12where
13    H1: Fn(&T1) -> usize,
14    H2: Fn(&T2) -> usize,
15{
16    #[allow(non_snake_case)]
17    #[inline]
18    pub fn call(&self, p: &(T1, T2)) -> usize {
19        let mut seed = 0;
20        hash_combine(&mut seed, (self.h1)(&p.0));
21        hash_combine(&mut seed, (self.h2)(&p.1));
22        seed
23    }
24}