Skip to content

Commit

Permalink
Implement Ord for TrieMap/TrieSet/SmallIntMap/Bitv/BitvSet
Browse files Browse the repository at this point in the history
  • Loading branch information
nham committed Jul 28, 2014
1 parent 935c88c commit 8ebd58c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/libcollections/bitv.rs
Expand Up @@ -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() {
Expand Down Expand Up @@ -963,7 +970,7 @@ impl<'a> RandomAccessIterator<bool> 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 {
Expand Down
7 changes: 7 additions & 0 deletions src/libcollections/smallintmap.rs
Expand Up @@ -380,6 +380,13 @@ impl<V: PartialOrd> PartialOrd for SmallIntMap<V> {
}
}

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, "{{"));
Expand Down
9 changes: 8 additions & 1 deletion src/libcollections/trie.rs
Expand Up @@ -100,6 +100,13 @@ impl<T: PartialOrd> PartialOrd for TrieMap<T> {
}
}

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, "{{"));
Expand Down Expand Up @@ -524,7 +531,7 @@ impl<S: Writer, T: Hash<S>> Hash<S> for TrieMap<T> {
/// set.clear();
/// assert!(set.is_empty());
/// ```
#[deriving(Clone, Hash, PartialEq, Eq, PartialOrd)]
#[deriving(Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
pub struct TrieSet {
map: TrieMap<()>
}
Expand Down

5 comments on commit 8ebd58c

@bors
Copy link
Contributor

@bors bors commented on 8ebd58c Jul 29, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from alexcrichton
at nham@8ebd58c

@bors
Copy link
Contributor

@bors bors commented on 8ebd58c Jul 29, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging nham/rust/collections_partialord = 8ebd58c into auto

@bors
Copy link
Contributor

@bors bors commented on 8ebd58c Jul 29, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nham/rust/collections_partialord = 8ebd58c merged ok, testing candidate = 7375f4d

@bors
Copy link
Contributor

@bors bors commented on 8ebd58c Jul 29, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 7375f4d

Please sign in to comment.