chronologic/relns/
ordering.rs1use std::cmp::Ordering;
2use crate::{TimeBounds, TimeInterval, TimePoint, TimeSet, TimeWindow};
3
4
5impl<T:TimePoint,TW> PartialEq<TW> for TimeInterval<T>
6 where
7 TW: TimeWindow<TimePoint=T>
8{
9 #[inline]
10 fn eq(&self, other: &TW) -> bool {
11 other.is_convex()
12 && self.lower == other.lower_bound()
13 && self.upper == other.upper_bound()
14 }
15}
16
17impl<T:TimePoint,TW> PartialEq<TW> for TimeSet<T>
18 where
19 TW: TimeWindow<TimePoint=T>
20{
21 #[inline]
22 fn eq(&self, other: &TW) -> bool {
23 self.iter().eq(other.iter())
24 }
25}
26
27macro_rules! timepartialcmp {
28 ($time:ident) => {
29 impl<T:TimePoint,TW> PartialOrd<TW> for $time<T>
30 where
31 TW: TimeWindow<TimePoint=T>
32 {
33 #[inline]
34 fn partial_cmp(&self, other: &TW) -> Option<Ordering>
35 {
36 if self.lt(other){
37 Some(Ordering::Less)
38 } else if self.gt(other) {
39 Some(Ordering::Greater)
40 } else if self.eq(other) {
41 Some(Ordering::Equal)
42 } else {
43 None
44 }
45 }
46
47 #[inline]
48 fn lt(&self, other: &TW) -> bool {
49 self.upper_bound() < other.lower_bound()
50 }
51
52 #[inline]
53 fn le(&self, other: &TW) -> bool {
54 self.lt(other) || self.eq(other)
55 }
56
57 #[inline]
58 fn gt(&self, other: &TW) -> bool {
59 self.lower_bound() > other.upper_bound()
60 }
61
62 #[inline]
63 fn ge(&self, other: &TW) -> bool {
64 self.gt(other) || self.eq(other)
65 }
66 }
67 }
68}
69
70timepartialcmp!(TimeInterval);
71timepartialcmp!(TimeSet);