added reverseExluded to match reverseUnbounded
This commit is contained in:
parent
5706f65ea3
commit
2f359534c3
@ -6,8 +6,10 @@ pub enum StartBound<T> {
|
||||
Included(T),
|
||||
Excluded(T),
|
||||
Unbounded,
|
||||
//a workaround type used only for allowing end-unbounded range searches
|
||||
//in overlapping()
|
||||
//workaround types used only as ends_bounds in meta-bound
|
||||
//StartBound range searches in overlapping() (non need for
|
||||
//reverseIncluded as it would be equivalent to normal included)
|
||||
ReverseExcluded(T),
|
||||
ReverseUnbounded,
|
||||
}
|
||||
|
||||
@ -15,11 +17,12 @@ impl<T> StartBound<T> {
|
||||
//when using this as an end value in a range search
|
||||
pub fn as_end_value(self) -> StartBound<T> {
|
||||
match self {
|
||||
//flipping is unnecessary
|
||||
StartBound::Included(point) => StartBound::Included(point),
|
||||
StartBound::Excluded(point) => StartBound::Excluded(point),
|
||||
//flip Unbounded with ReverseUnbounded
|
||||
//flip to Reverses
|
||||
StartBound::Excluded(point) => StartBound::ReverseExcluded(point),
|
||||
StartBound::Unbounded => StartBound::ReverseUnbounded,
|
||||
StartBound::ReverseUnbounded => panic!("unsuitable operation"),
|
||||
_ => panic!("unsuitable operation"),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -34,26 +37,33 @@ where
|
||||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||
match (self, other) {
|
||||
(StartBound::Included(start1), StartBound::Included(start2)) => start1.partial_cmp(start2),
|
||||
(StartBound::Excluded(start1), StartBound::Excluded(start2)) => start1.partial_cmp(start2),
|
||||
|
||||
(StartBound::Included(start1), StartBound::Excluded(start2)) => partial_cmp_with_priority(start1, start2, true),
|
||||
(StartBound::Excluded(start1), StartBound::Included(start2)) => partial_cmp_with_priority(start1, start2, false),
|
||||
|
||||
(StartBound::Included(start1), StartBound::ReverseExcluded(start2)) => partial_cmp_with_priority(start1, start2, false),
|
||||
(StartBound::Included(_), StartBound::ReverseUnbounded) => Some(Ordering::Less),
|
||||
(StartBound::Included(_), StartBound::Unbounded) => Some(Ordering::Greater),
|
||||
|
||||
(StartBound::Excluded(start1), StartBound::Excluded(start2)) => start1.partial_cmp(start2),
|
||||
(StartBound::Excluded(start1), StartBound::Included(start2)) => partial_cmp_with_priority(start1, start2, false),
|
||||
(StartBound::Excluded(start1), StartBound::ReverseExcluded(start2)) => partial_cmp_with_priority(start1, start2, false),
|
||||
(StartBound::Excluded(_), StartBound::Unbounded) => Some(Ordering::Greater),
|
||||
(StartBound::Excluded(_), StartBound::ReverseUnbounded) => Some(Ordering::Less),
|
||||
|
||||
(StartBound::Unbounded, StartBound::Included(_)) => Some(Ordering::Less),
|
||||
(StartBound::Unbounded, StartBound::Excluded(_)) => Some(Ordering::Less),
|
||||
(StartBound::Unbounded, StartBound::ReverseExcluded(_)) => Some(Ordering::Less),
|
||||
(StartBound::Unbounded, StartBound::Unbounded) => Some(Ordering::Equal),
|
||||
(StartBound::Unbounded, StartBound::ReverseUnbounded) => Some(Ordering::Less),
|
||||
|
||||
(StartBound::ReverseExcluded(start1), StartBound::ReverseExcluded(start2)) => start1.partial_cmp(start2),
|
||||
(StartBound::ReverseExcluded(start1), StartBound::Included(start2)) => partial_cmp_with_priority(start1, start2, true),
|
||||
(StartBound::ReverseExcluded(start1), StartBound::Excluded(start2)) => partial_cmp_with_priority(start1, start2, true),
|
||||
(StartBound::ReverseExcluded(_), StartBound::Unbounded) => Some(Ordering::Greater),
|
||||
(StartBound::ReverseExcluded(_), StartBound::ReverseUnbounded) => Some(Ordering::Less),
|
||||
|
||||
(StartBound::Included(_), StartBound::ReverseUnbounded) => Some(Ordering::Less),
|
||||
(StartBound::Excluded(_), StartBound::ReverseUnbounded) => Some(Ordering::Less),
|
||||
(StartBound::ReverseUnbounded, StartBound::Included(_)) => Some(Ordering::Greater),
|
||||
(StartBound::ReverseUnbounded, StartBound::Excluded(_)) => Some(Ordering::Greater),
|
||||
|
||||
|
||||
(StartBound::Unbounded, StartBound::Unbounded) => Some(Ordering::Equal),
|
||||
(StartBound::ReverseUnbounded, StartBound::ReverseExcluded(_)) => Some(Ordering::Greater),
|
||||
(StartBound::ReverseUnbounded, StartBound::ReverseUnbounded) => Some(Ordering::Equal),
|
||||
|
||||
(StartBound::Unbounded, StartBound::ReverseUnbounded) => Some(Ordering::Less),
|
||||
(StartBound::ReverseUnbounded, StartBound::Unbounded) => Some(Ordering::Greater),
|
||||
}
|
||||
}
|
||||
@ -104,7 +114,7 @@ impl<T> From<StartBound<T>> for Bound<T> {
|
||||
StartBound::Included(point) => Bound::Included(point),
|
||||
StartBound::Excluded(point) => Bound::Excluded(point),
|
||||
StartBound::Unbounded => Bound::Unbounded,
|
||||
StartBound::ReverseUnbounded => panic!("unsuitable operation"),
|
||||
_ => panic!("unsuitable operation"),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -116,6 +126,7 @@ mod tests {
|
||||
#[rustfmt::skip]
|
||||
#[test]
|
||||
fn mass_start_bound_partial_ord_test() {
|
||||
//Included
|
||||
assert!(StartBound::Included(2) == StartBound::Included(2));
|
||||
assert!(StartBound::Included(2) <= StartBound::Included(2));
|
||||
assert!(StartBound::Included(2) >= StartBound::Included(2));
|
||||
@ -126,37 +137,48 @@ mod tests {
|
||||
assert!(StartBound::Included(0) < StartBound::Excluded(2));
|
||||
assert!(StartBound::Included(2) > StartBound::Excluded(0));
|
||||
|
||||
assert!(StartBound::Excluded(2) > StartBound::Included(2));
|
||||
assert!(StartBound::Excluded(2) > StartBound::Included(0));
|
||||
assert!(StartBound::Excluded(0) < StartBound::Included(2));
|
||||
assert!(StartBound::Included(2) > StartBound::Unbounded);
|
||||
|
||||
assert!(StartBound::Included(2) > StartBound::ReverseExcluded(2));
|
||||
assert!(StartBound::Included(0) < StartBound::ReverseExcluded(2));
|
||||
assert!(StartBound::Included(2) > StartBound::ReverseExcluded(0));
|
||||
|
||||
assert!(StartBound::Included(2) < StartBound::ReverseUnbounded);
|
||||
|
||||
//Exluded
|
||||
assert!(StartBound::Excluded(2) == StartBound::Excluded(2));
|
||||
assert!(StartBound::Excluded(2) <= StartBound::Excluded(2));
|
||||
assert!(StartBound::Excluded(2) >= StartBound::Excluded(2));
|
||||
assert!(StartBound::Excluded(0) < StartBound::Excluded(2));
|
||||
assert!(StartBound::Excluded(2) > StartBound::Excluded(0));
|
||||
|
||||
assert!(StartBound::Included(2) > StartBound::Unbounded);
|
||||
assert!(StartBound::Excluded(2) > StartBound::Unbounded);
|
||||
|
||||
assert!(StartBound::Unbounded < StartBound::Included(2));
|
||||
assert!(StartBound::Unbounded < StartBound::Excluded(2));
|
||||
assert!(StartBound::Excluded(2) > StartBound::ReverseExcluded(2));
|
||||
assert!(StartBound::Excluded(2) > StartBound::ReverseExcluded(0));
|
||||
assert!(StartBound::Excluded(0) < StartBound::ReverseExcluded(2));
|
||||
|
||||
assert!(StartBound::Included(2) < StartBound::ReverseUnbounded);
|
||||
assert!(StartBound::Excluded(2) < StartBound::ReverseUnbounded);
|
||||
|
||||
assert!(StartBound::ReverseUnbounded > StartBound::Included(2));
|
||||
assert!(StartBound::ReverseUnbounded > StartBound::Excluded(2));
|
||||
|
||||
//Unbounded
|
||||
assert!(StartBound::Unbounded::<u8> == StartBound::Unbounded);
|
||||
assert!(StartBound::Unbounded::<u8> <= StartBound::Unbounded);
|
||||
assert!(StartBound::Unbounded::<u8> >= StartBound::Unbounded);
|
||||
|
||||
assert!(StartBound::Unbounded < StartBound::ReverseExcluded(2));
|
||||
|
||||
assert!(StartBound::Unbounded::<u8> < StartBound::ReverseUnbounded);
|
||||
|
||||
//ReverseExcluded
|
||||
assert!(StartBound::ReverseExcluded(2) == StartBound::ReverseExcluded(2));
|
||||
assert!(StartBound::ReverseExcluded(2) <= StartBound::ReverseExcluded(2));
|
||||
assert!(StartBound::ReverseExcluded(2) >= StartBound::ReverseExcluded(2));
|
||||
assert!(StartBound::ReverseExcluded(0) < StartBound::ReverseExcluded(2));
|
||||
assert!(StartBound::ReverseExcluded(2) > StartBound::ReverseExcluded(0));
|
||||
|
||||
//ReverseUnbounded
|
||||
assert!(StartBound::ReverseUnbounded::<u8> == StartBound::ReverseUnbounded);
|
||||
assert!(StartBound::ReverseUnbounded::<u8> <= StartBound::ReverseUnbounded);
|
||||
assert!(StartBound::ReverseUnbounded::<u8> >= StartBound::ReverseUnbounded);
|
||||
|
||||
assert!(StartBound::Unbounded::<u8> < StartBound::ReverseUnbounded);
|
||||
assert!(StartBound::ReverseUnbounded::<u8> > StartBound::Unbounded);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user