rithm/fraction/
hash.rs

1use std::hash::{Hash, Hasher};
2
3use crate::big_int::BigInt;
4
5use super::types::Fraction;
6
7impl<Digit, const DIGIT_BITNESS: usize> Hash
8    for Fraction<BigInt<Digit, DIGIT_BITNESS>>
9where
10    BigInt<Digit, DIGIT_BITNESS>: Hash,
11{
12    fn hash<H: Hasher>(&self, state: &mut H) {
13        self.numerator.hash(state);
14        self.denominator.hash(state);
15    }
16}
17
18macro_rules! integer_fraction_hash_impl {
19    ($($integer:ty)*) => ($(
20        impl Hash for Fraction<$integer> {
21            fn hash<H: Hasher>(&self, state: &mut H) {
22                self.numerator.hash(state);
23                self.denominator.hash(state);
24            }
25        }
26    )*)
27}
28
29integer_fraction_hash_impl!(
30    i8 i16 i32 i64 i128 isize u8 u16 u32 u64 u128 usize
31);