Skip to content

Commit 8ebd58c

Browse files
committed
Implement Ord for TrieMap/TrieSet/SmallIntMap/Bitv/BitvSet
1 parent 935c88c commit 8ebd58c

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

src/libcollections/bitv.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,13 @@ impl PartialOrd for Bitv {
838838
}
839839
}
840840

841+
impl Ord for Bitv {
842+
#[inline]
843+
fn cmp(&self, other: &Bitv) -> Ordering {
844+
iter::order::cmp(self.iter(), other.iter())
845+
}
846+
}
847+
841848
impl fmt::Show for Bitv {
842849
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
843850
for bit in self.iter() {
@@ -963,7 +970,7 @@ impl<'a> RandomAccessIterator<bool> for Bits<'a> {
963970
/// assert!(bv.eq_vec([true, true, false, true,
964971
/// false, false, false, false]));
965972
/// ```
966-
#[deriving(Clone, PartialEq, Eq, PartialOrd)]
973+
#[deriving(Clone, PartialEq, Eq, PartialOrd, Ord)]
967974
pub struct BitvSet(Bitv);
968975

969976
impl Default for BitvSet {

src/libcollections/smallintmap.rs

+7
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,13 @@ impl<V: PartialOrd> PartialOrd for SmallIntMap<V> {
380380
}
381381
}
382382

383+
impl<V: Ord> Ord for SmallIntMap<V> {
384+
#[inline]
385+
fn cmp(&self, other: &SmallIntMap<V>) -> Ordering {
386+
iter::order::cmp(self.iter(), other.iter())
387+
}
388+
}
389+
383390
impl<V: fmt::Show> fmt::Show for SmallIntMap<V> {
384391
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
385392
try!(write!(f, "{{"));

src/libcollections/trie.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,13 @@ impl<T: PartialOrd> PartialOrd for TrieMap<T> {
100100
}
101101
}
102102

103+
impl<T: Ord> Ord for TrieMap<T> {
104+
#[inline]
105+
fn cmp(&self, other: &TrieMap<T>) -> Ordering {
106+
iter::order::cmp(self.iter(), other.iter())
107+
}
108+
}
109+
103110
impl<T: Show> Show for TrieMap<T> {
104111
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
105112
try!(write!(f, "{{"));
@@ -524,7 +531,7 @@ impl<S: Writer, T: Hash<S>> Hash<S> for TrieMap<T> {
524531
/// set.clear();
525532
/// assert!(set.is_empty());
526533
/// ```
527-
#[deriving(Clone, Hash, PartialEq, Eq, PartialOrd)]
534+
#[deriving(Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
528535
pub struct TrieSet {
529536
map: TrieMap<()>
530537
}

0 commit comments

Comments
 (0)