From 8ebd58cedf616580a4052ad6df1ce74cfcd520c0 Mon Sep 17 00:00:00 2001 From: nham Date: Mon, 28 Jul 2014 02:53:44 -0400 Subject: [PATCH] Implement Ord for TrieMap/TrieSet/SmallIntMap/Bitv/BitvSet --- src/libcollections/bitv.rs | 9 ++++++++- src/libcollections/smallintmap.rs | 7 +++++++ src/libcollections/trie.rs | 9 ++++++++- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/libcollections/bitv.rs b/src/libcollections/bitv.rs index 55caf807b4fd4..3e1160b45eee4 100644 --- a/src/libcollections/bitv.rs +++ b/src/libcollections/bitv.rs @@ -838,6 +838,13 @@ impl PartialOrd for Bitv { } } +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 @@ impl<'a> RandomAccessIterator for Bits<'a> { /// 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 { diff --git a/src/libcollections/smallintmap.rs b/src/libcollections/smallintmap.rs index 5acabecb6ee51..f567c5777b171 100644 --- a/src/libcollections/smallintmap.rs +++ b/src/libcollections/smallintmap.rs @@ -380,6 +380,13 @@ impl PartialOrd for SmallIntMap { } } +impl Ord for SmallIntMap { + #[inline] + fn cmp(&self, other: &SmallIntMap) -> Ordering { + iter::order::cmp(self.iter(), other.iter()) + } +} + impl fmt::Show for SmallIntMap { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { try!(write!(f, "{{")); diff --git a/src/libcollections/trie.rs b/src/libcollections/trie.rs index 5d6a9080374e7..cd011b0e01339 100644 --- a/src/libcollections/trie.rs +++ b/src/libcollections/trie.rs @@ -100,6 +100,13 @@ impl PartialOrd for TrieMap { } } +impl Ord for TrieMap { + #[inline] + fn cmp(&self, other: &TrieMap) -> Ordering { + iter::order::cmp(self.iter(), other.iter()) + } +} + impl Show for TrieMap { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { try!(write!(f, "{{")); @@ -524,7 +531,7 @@ impl> Hash for TrieMap { /// set.clear(); /// assert!(set.is_empty()); /// ``` -#[deriving(Clone, Hash, PartialEq, Eq, PartialOrd)] +#[deriving(Clone, Hash, PartialEq, Eq, PartialOrd, Ord)] pub struct TrieSet { map: TrieMap<()> }