Skip to main content

nekolib/utils/
op_min.rs

1//! 最小値に関する wrapper クラス。
2
3use super::super::traits::binop;
4use super::super::traits::max;
5
6use std::fmt::Debug;
7
8use binop::{Associative, Commutative, Identity, Magma};
9use max::Max;
10
11/// 最小値を返す演算を持つ。
12///
13/// 単位元は [`Max`] で定義する。
14///
15/// [`Max`]: ../../traits/max/trait.Max.html
16#[derive(Clone, Copy, Debug, Eq, PartialEq)]
17pub enum OpMin<T> {
18    OpMinV,
19    _Marker(T),
20}
21pub use OpMin::OpMinV;
22
23impl<T> Default for OpMin<T> {
24    fn default() -> Self { OpMinV }
25}
26
27impl<T> Magma for OpMin<T>
28where
29    T: Ord + Eq + Sized,
30{
31    type Set = T;
32    fn op(&self, x: Self::Set, y: Self::Set) -> Self::Set { x.min(y) }
33}
34impl<T> Identity for OpMin<T>
35where
36    T: Ord + Eq + Sized + Max,
37{
38    fn id(&self) -> Self::Set { <T as Max>::max() }
39}
40
41impl<T> Associative for OpMin<T> where T: Ord + Eq + Sized {}
42impl<T> Commutative for OpMin<T> where T: Ord + Eq + Sized {}