about summary refs log tree commit diff
diff options
context:
space:
mode:
authorblake2-ppc <blake2-ppc>2013-08-08 22:07:21 +0200
committerblake2-ppc <blake2-ppc>2013-08-08 22:07:21 +0200
commita2e3cdfc362e27152bb6a3ad6ba0cefc13f061a9 (patch)
tree09cb61e2483138ef6be6303b2d4305b045b3e602
parent5d9fd882b7ebb911daf0f21ca81f4acc599c2686 (diff)
downloadrust-a2e3cdfc362e27152bb6a3ad6ba0cefc13f061a9.tar.gz
rust-a2e3cdfc362e27152bb6a3ad6ba0cefc13f061a9.zip
extra::dlist: Use iterator::order for sequence ordering
-rw-r--r--src/libextra/dlist.rs64
1 files changed, 61 insertions, 3 deletions
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::cast;
 use std::ptr;
 use std::util;
 use std::iterator::{FromIterator, Extendable, Invert};
+use std::iterator;
 
 use container::Deque;
 
@@ -589,12 +590,27 @@ impl<A, T: Iterator<A>> Extendable<A, T> for DList<A> {
 impl<A: Eq> Eq for DList<A> {
     fn eq(&self, other: &DList<A>) -> 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<A>) -> bool {
-        !self.eq(other)
+        self.len() != other.len() &&
+            iterator::order::ne(self.iter(), other.iter())
+    }
+}
+
+impl<A: Eq + Ord> Ord for DList<A> {
+    fn lt(&self, other: &DList<A>) -> bool {
+        iterator::order::lt(self.iter(), other.iter())
+    }
+    fn le(&self, other: &DList<A>) -> bool {
+        iterator::order::le(self.iter(), other.iter())
+    }
+    fn gt(&self, other: &DList<A>) -> bool {
+        iterator::order::gt(self.iter(), other.iter())
+    }
+    fn ge(&self, other: &DList<A>) -> bool {
+        iterator::order::ge(self.iter(), other.iter())
     }
 }
 
@@ -965,6 +981,48 @@ mod tests {
     }
 
     #[test]
+    fn test_ord() {
+        let n: DList<int> = 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 {
             fuzz_test(3);