cp_library_rs/algebraic_structure/
operation.rs1use std::{fmt::Debug, marker::PhantomData, ops::Rem};
4
5use num_traits::Zero;
6
7#[derive(Debug)]
9pub struct Min<T>(PhantomData<T>);
10
11#[derive(Debug, Clone)]
13pub struct Max<T>(PhantomData<T>);
14
15#[derive(Debug, Clone)]
17pub struct MinMax<T>(PhantomData<T>);
18
19#[derive(Debug, Clone)]
21pub struct Add<T>(PhantomData<T>);
22
23#[derive(Debug, Clone)]
25pub struct WrappingAdd;
26
27#[derive(Debug, Clone)]
29pub struct Mul<T>(PhantomData<T>);
30
31#[derive(Debug, Clone)]
33pub struct Xor;
34
35#[derive(Debug)]
37pub struct GCD<T>(PhantomData<T>);
38impl<T: Clone + PartialEq + Zero + Rem<T, Output = T>> GCD<T> {
39 pub fn gcd(a: &T, b: &T) -> T {
41 if b.is_zero() {
42 a.clone()
43 } else {
44 Self::gcd(b, &a.clone().rem(b.clone()))
45 }
46 }
47}