Skip to content

Commit

Permalink
collections: Implement Ord for DList, RingBuf, TreeMap, TreeSet
Browse files Browse the repository at this point in the history
  • Loading branch information
nham committed Aug 1, 2014
1 parent 25acfde commit 3737c53
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/libcollections/dlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,13 @@ impl<A: PartialOrd> PartialOrd for DList<A> {
}
}

impl<A: Ord> Ord for DList<A> {
#[inline]
fn cmp(&self, other: &DList<A>) -> Ordering {
iter::order::cmp(self.iter(), other.iter())
}
}

impl<A: Clone> Clone for DList<A> {
fn clone(&self) -> DList<A> {
self.iter().map(|x| x.clone()).collect()
Expand Down
7 changes: 7 additions & 0 deletions src/libcollections/ringbuf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,13 @@ impl<A: PartialOrd> PartialOrd for RingBuf<A> {
}
}

impl<A: Ord> Ord for RingBuf<A> {
#[inline]
fn cmp(&self, other: &RingBuf<A>) -> Ordering {
iter::order::cmp(self.iter(), other.iter())
}
}

impl<S: Writer, A: Hash<S>> Hash<S> for RingBuf<A> {
fn hash(&self, state: &mut S) {
self.len().hash(state);
Expand Down
14 changes: 14 additions & 0 deletions src/libcollections/treemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,13 @@ impl<K: Ord, V: PartialOrd> PartialOrd for TreeMap<K, V> {
}
}

impl<K: Ord, V: Ord> Ord for TreeMap<K, V> {
#[inline]
fn cmp(&self, other: &TreeMap<K, V>) -> Ordering {
iter::order::cmp(self.iter(), other.iter())
}
}

impl<K: Ord + Show, V: Show> Show for TreeMap<K, V> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
try!(write!(f, "{{"));
Expand Down Expand Up @@ -1021,6 +1028,13 @@ impl<T: Ord> PartialOrd for TreeSet<T> {
}
}

impl<T: Ord> Ord for TreeSet<T> {
#[inline]
fn cmp(&self, other: &TreeSet<T>) -> Ordering {
iter::order::cmp(self.iter(), other.iter())
}
}

impl<T: Ord + Show> Show for TreeSet<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
try!(write!(f, "{{"));
Expand Down

0 comments on commit 3737c53

Please sign in to comment.