Skip to main content

nekolib/utils/
op_gcd.rs

1use super::super::math::gcd;
2use super::super::traits::additive;
3use super::super::traits::binop;
4use std::fmt::Debug;
5
6use additive::Zero;
7use binop::{Associative, Commutative, Identity, Magma};
8use gcd::Gcd;
9
10#[derive(Clone, Copy, Debug, Eq, PartialEq)]
11pub enum OpGcd<T> {
12    OpGcdV,
13    _Marker(T),
14}
15pub use OpGcd::OpGcdV;
16
17impl<T> Default for OpGcd<T> {
18    fn default() -> Self { OpGcdV }
19}
20
21impl<T> Magma for OpGcd<T>
22where
23    T: Gcd + Eq + Sized,
24{
25    type Set = T;
26    fn op(&self, x: Self::Set, y: Self::Set) -> Self::Set { x.gcd(y) }
27}
28impl<T> Identity for OpGcd<T>
29where
30    T: Gcd + Eq + Zero + Sized,
31{
32    fn id(&self) -> Self::Set { T::zero() }
33}
34
35impl<T> Associative for OpGcd<T> where T: Gcd + Eq + Sized {}
36impl<T> Commutative for OpGcd<T> where T: Gcd + Eq + Sized {}