diff --git a/src/libextra/dlist.rs b/src/libextra/dlist.rs index b0839a55795..6e8bd01af22 100644 --- a/src/libextra/dlist.rs +++ b/src/libextra/dlist.rs @@ -26,6 +26,7 @@ use std::ptr; use std::util; use std::iterator::{FromIterator, Extendable, Invert}; +use std::iterator; use container::Deque; @@ -589,12 +590,27 @@ fn extend(&mut self, iterator: &mut T) { impl Eq for DList { fn eq(&self, other: &DList) -> bool { self.len() == other.len() && - self.iter().zip(other.iter()).all(|(a, b)| a.eq(b)) + iterator::order::eq(self.iter(), other.iter()) } - #[inline] fn ne(&self, other: &DList) -> bool { - !self.eq(other) + self.len() != other.len() && + iterator::order::ne(self.iter(), other.iter()) + } +} + +impl Ord for DList { + fn lt(&self, other: &DList) -> bool { + iterator::order::lt(self.iter(), other.iter()) + } + fn le(&self, other: &DList) -> bool { + iterator::order::le(self.iter(), other.iter()) + } + fn gt(&self, other: &DList) -> bool { + iterator::order::gt(self.iter(), other.iter()) + } + fn ge(&self, other: &DList) -> bool { + iterator::order::ge(self.iter(), other.iter()) } } @@ -964,6 +980,48 @@ fn test_eq() { assert_eq!(&n, &m); } + #[test] + fn test_ord() { + let n: DList = list_from([]); + let m = list_from([1,2,3]); + assert!(n < m); + assert!(m > n); + assert!(n <= n); + assert!(n >= n); + } + + #[test] + fn test_ord_nan() { + let nan = 0.0/0.0; + let n = list_from([nan]); + let m = list_from([nan]); + assert!(!(n < m)); + assert!(!(n > m)); + assert!(!(n <= m)); + assert!(!(n >= m)); + + let n = list_from([nan]); + let one = list_from([1.0]); + assert!(!(n < one)); + assert!(!(n > one)); + assert!(!(n <= one)); + assert!(!(n >= one)); + + let u = list_from([1.0,2.0,nan]); + let v = list_from([1.0,2.0,3.0]); + assert!(!(u < v)); + assert!(!(u > v)); + assert!(!(u <= v)); + assert!(!(u >= v)); + + let s = list_from([1.0,2.0,4.0,2.0]); + let t = list_from([1.0,2.0,3.0,2.0]); + assert!(!(s < t)); + assert!(s > one); + assert!(!(s <= one)); + assert!(s >= one); + } + #[test] fn test_fuzz() { do 25.times {