haar_lib/algebra/
min_max.rs1use std::marker::PhantomData;
3
4pub use crate::algebra::traits::*;
5use crate::impl_algebra;
6
7#[derive(Clone, Copy, Default, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
9pub struct Min<T>(PhantomData<T>);
10impl<T> Min<T> {
11 pub fn new() -> Self {
13 Self(PhantomData)
14 }
15}
16
17#[derive(Clone, Copy, Default, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
19pub struct Max<T>(PhantomData<T>);
20impl<T> Max<T> {
21 pub fn new() -> Self {
23 Self(PhantomData)
24 }
25}
26
27macro_rules! implement {
28 ($($t:tt),*) => {
29 $(impl_algebra!(Min<$t>; set: $t; op: |_, a: $t, b: $t| a.min(b);
30 id: |_| $t::MAX; commu; assoc; idem;);)*
31 $(impl_algebra!(Max<$t>; set: $t; op: |_, a: $t, b: $t| a.max(b);
32 id: |_| $t::MIN; commu; assoc; idem;);)*
33
34 $(impl Ordered for Min<$t> {})*
35 $(impl Ordered for Max<$t> {})*
36 };
37}
38
39implement!(i8, i16, i32, i64, i128, isize, u8, u16, u32, u64, u128, usize);