haar_lib/algebra/
gcd_lcm.rs

1//! GCD・LCM
2pub use crate::algebra::traits::*;
3use crate::impl_algebra;
4use crate::math::gcd_lcm::*;
5use std::marker::PhantomData;
6
7/// GCDモノイド
8#[derive(Clone, Copy, Debug, Default, Hash, PartialEq, Eq, PartialOrd, Ord)]
9pub struct GCD<T>(PhantomData<T>);
10/// LCMモノイド
11#[derive(Clone, Copy, Debug, Default, Hash, PartialEq, Eq, PartialOrd, Ord)]
12pub struct LCM<T>(PhantomData<T>);
13
14impl<T> GCD<T> {
15    /// `GCD`を返す。
16    pub fn new() -> Self {
17        Self(PhantomData)
18    }
19}
20impl<T> LCM<T> {
21    /// `LCM`を返す。
22    pub fn new() -> Self {
23        Self(PhantomData)
24    }
25}
26
27macro_rules! implement {
28    ($($t:ty),*) => {
29        $(
30            impl_algebra!(GCD<$t>; set: $t; op: |_, a: $t, b: $t| a.gcd(b);
31                          id: |_| 0 as $t; commu; assoc; idem;);
32            impl_algebra!(LCM<$t>; set: $t; op: |_, a: $t, b: $t| a.lcm(b);
33                          id: |_| 1 as $t; commu; assoc; idem;);
34        )*
35    };
36}
37
38implement!(i8, i16, i32, i64, i128, isize, u8, u16, u32, u64, u128, usize);