]> git.lizzy.rs Git - rust.git/commitdiff
Implement Ord for TrieMap/TrieSet/SmallIntMap/Bitv/BitvSet
authornham <hamann.nick@gmail.com>
Mon, 28 Jul 2014 06:53:44 +0000 (02:53 -0400)
committernham <hamann.nick@gmail.com>
Mon, 28 Jul 2014 06:53:44 +0000 (02:53 -0400)
src/libcollections/bitv.rs
src/libcollections/smallintmap.rs
src/libcollections/trie.rs

index 55caf807b4fd449b13831daa1ebede02df96ff10..3e1160b45eee40d558a3f43dbf277d31e358f4eb 100644 (file)
@@ -838,6 +838,13 @@ fn partial_cmp(&self, other: &Bitv) -> Option<Ordering> {
     }
 }
 
+impl Ord for Bitv {
+    #[inline]
+    fn cmp(&self, other: &Bitv) -> Ordering {
+        iter::order::cmp(self.iter(), other.iter())
+    }
+}
+
 impl fmt::Show for Bitv {
     fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
         for bit in self.iter() {
@@ -963,7 +970,7 @@ fn idx(&mut self, index: uint) -> Option<bool> {
 /// assert!(bv.eq_vec([true, true, false, true,
 ///                    false, false, false, false]));
 /// ```
-#[deriving(Clone, PartialEq, Eq, PartialOrd)]
+#[deriving(Clone, PartialEq, Eq, PartialOrd, Ord)]
 pub struct BitvSet(Bitv);
 
 impl Default for BitvSet {
index 5acabecb6ee513943e6173be55bcef5b8154e892..f567c5777b1711e163d2474bd3ca6a8713673738 100644 (file)
@@ -380,6 +380,13 @@ fn partial_cmp(&self, other: &SmallIntMap<V>) -> Option<Ordering> {
     }
 }
 
+impl<V: Ord> Ord for SmallIntMap<V> {
+    #[inline]
+    fn cmp(&self, other: &SmallIntMap<V>) -> Ordering {
+        iter::order::cmp(self.iter(), other.iter())
+    }
+}
+
 impl<V: fmt::Show> fmt::Show for SmallIntMap<V> {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         try!(write!(f, "{{"));
index 5d6a9080374e764f70e42da1b968d490d84c1e6b..cd011b0e0133972d0eb13f91d4144fee13c5c2d7 100644 (file)
@@ -100,6 +100,13 @@ fn partial_cmp(&self, other: &TrieMap<T>) -> Option<Ordering> {
     }
 }
 
+impl<T: Ord> Ord for TrieMap<T> {
+    #[inline]
+    fn cmp(&self, other: &TrieMap<T>) -> Ordering {
+        iter::order::cmp(self.iter(), other.iter())
+    }
+}
+
 impl<T: Show> Show for TrieMap<T> {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         try!(write!(f, "{{"));
@@ -524,7 +531,7 @@ fn hash(&self, state: &mut S) {
 /// set.clear();
 /// assert!(set.is_empty());
 /// ```
-#[deriving(Clone, Hash, PartialEq, Eq, PartialOrd)]
+#[deriving(Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
 pub struct TrieSet {
     map: TrieMap<()>
 }