~ruther/ctu-fee-eoa

ref: c7d027ecf955937649ef77c793dff08cfd4a56d5 ctu-fee-eoa/env/src/comparison/mod.rs -rw-r--r-- 619 bytes
c7d027ec — Rutherther feat: add new terminating conditions (or, lower than, maximum cycles) a month ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
pub trait BetterThanOperator<T> {
    fn better_than(self: &Self, a: &T, b: &T) -> bool;
}

pub struct MinimizingOperator;
impl MinimizingOperator {
    pub fn new() -> Self {
        Self
    }
}

impl<T> BetterThanOperator<T> for MinimizingOperator
    where T: PartialOrd
{
    fn better_than(self: &Self, a: &T, b: &T) -> bool {
        a < b
    }
}

pub struct MaximizingOperator;
impl MaximizingOperator {
    pub fn new() -> Self {
        Self
    }
}

impl<T> BetterThanOperator<T> for MaximizingOperator
    where T: PartialOrd
{
    fn better_than(self: &Self, a: &T, b: &T) -> bool {
        a > b
    }
}