Skip to content

Commit 3737c53

Browse files
committed
collections: Implement Ord for DList, RingBuf, TreeMap, TreeSet
1 parent 25acfde commit 3737c53

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

src/libcollections/dlist.rs

+7
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,13 @@ impl<A: PartialOrd> PartialOrd for DList<A> {
691691
}
692692
}
693693

694+
impl<A: Ord> Ord for DList<A> {
695+
#[inline]
696+
fn cmp(&self, other: &DList<A>) -> Ordering {
697+
iter::order::cmp(self.iter(), other.iter())
698+
}
699+
}
700+
694701
impl<A: Clone> Clone for DList<A> {
695702
fn clone(&self) -> DList<A> {
696703
self.iter().map(|x| x.clone()).collect()

src/libcollections/ringbuf.rs

+7
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,13 @@ impl<A: PartialOrd> PartialOrd for RingBuf<A> {
460460
}
461461
}
462462

463+
impl<A: Ord> Ord for RingBuf<A> {
464+
#[inline]
465+
fn cmp(&self, other: &RingBuf<A>) -> Ordering {
466+
iter::order::cmp(self.iter(), other.iter())
467+
}
468+
}
469+
463470
impl<S: Writer, A: Hash<S>> Hash<S> for RingBuf<A> {
464471
fn hash(&self, state: &mut S) {
465472
self.len().hash(state);

src/libcollections/treemap.rs

+14
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,13 @@ impl<K: Ord, V: PartialOrd> PartialOrd for TreeMap<K, V> {
182182
}
183183
}
184184

185+
impl<K: Ord, V: Ord> Ord for TreeMap<K, V> {
186+
#[inline]
187+
fn cmp(&self, other: &TreeMap<K, V>) -> Ordering {
188+
iter::order::cmp(self.iter(), other.iter())
189+
}
190+
}
191+
185192
impl<K: Ord + Show, V: Show> Show for TreeMap<K, V> {
186193
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
187194
try!(write!(f, "{{"));
@@ -1021,6 +1028,13 @@ impl<T: Ord> PartialOrd for TreeSet<T> {
10211028
}
10221029
}
10231030

1031+
impl<T: Ord> Ord for TreeSet<T> {
1032+
#[inline]
1033+
fn cmp(&self, other: &TreeSet<T>) -> Ordering {
1034+
iter::order::cmp(self.iter(), other.iter())
1035+
}
1036+
}
1037+
10241038
impl<T: Ord + Show> Show for TreeSet<T> {
10251039
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10261040
try!(write!(f, "{{"));

0 commit comments

Comments
 (0)