haar_lib/algebra/semiring/
xor_and.rs

1//! XorとAndの半環
2pub use crate::algebra::semiring::Semiring;
3
4/// XorとAndの半環
5#[derive(Clone, Copy, Default, Debug, PartialEq, Eq)]
6pub struct XorAndSemiring<T>(pub T);
7
8macro_rules! impl_semiring {
9    ($($t:ty),*) => {
10        $(impl Semiring for XorAndSemiring<$t> {
11            fn zero() -> Self {
12                Self(0)
13            }
14            fn one() -> Self {
15                Self(!0)
16            }
17            fn add(self, b: Self) -> Self {
18                Self(self.0 ^ b.0)
19            }
20            fn mul(self, b: Self) -> Self {
21                Self(self.0 & b.0)
22            }
23        })*
24    };
25}
26
27impl_semiring!(u8, u16, u32, u64, u128, usize);