From: nham Date: Mon, 28 Jul 2014 06:53:44 +0000 (-0400) Subject: Implement Ord for TrieMap/TrieSet/SmallIntMap/Bitv/BitvSet X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=8ebd58cedf616580a4052ad6df1ce74cfcd520c0;p=rust.git Implement Ord for TrieMap/TrieSet/SmallIntMap/Bitv/BitvSet --- diff --git a/src/libcollections/bitv.rs b/src/libcollections/bitv.rs index 55caf807b4f..3e1160b45ee 100644 --- a/src/libcollections/bitv.rs +++ b/src/libcollections/bitv.rs @@ -838,6 +838,13 @@ fn partial_cmp(&self, other: &Bitv) -> Option { } } +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 { /// 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 5acabecb6ee..f567c5777b1 100644 --- a/src/libcollections/smallintmap.rs +++ b/src/libcollections/smallintmap.rs @@ -380,6 +380,13 @@ fn partial_cmp(&self, other: &SmallIntMap) -> Option { } } +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 5d6a9080374..cd011b0e013 100644 --- a/src/libcollections/trie.rs +++ b/src/libcollections/trie.rs @@ -100,6 +100,13 @@ fn partial_cmp(&self, other: &TrieMap) -> Option { } } +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 @@ 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<()> }