Skip to main content

nekolib/utils/
op_max.rs

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