diff options
| author | nham <hamann.nick@gmail.com> | 2014-08-01 16:22:48 -0400 |
|---|---|---|
| committer | nham <hamann.nick@gmail.com> | 2014-08-01 16:51:26 -0400 |
| commit | 3737c537c3bb1aa96ddfd934fd4c48839249f5eb (patch) | |
| tree | 162a0fe0aa2357ac83d6c25bcd29bdabae70c59d | |
| parent | 25acfde39864304c902293328f3492871ad0cbc8 (diff) | |
| download | rust-3737c537c3bb1aa96ddfd934fd4c48839249f5eb.tar.gz rust-3737c537c3bb1aa96ddfd934fd4c48839249f5eb.zip | |
collections: Implement Ord for DList, RingBuf, TreeMap, TreeSet
| -rw-r--r-- | src/libcollections/dlist.rs | 7 | ||||
| -rw-r--r-- | src/libcollections/ringbuf.rs | 7 | ||||
| -rw-r--r-- | src/libcollections/treemap.rs | 14 |
3 files changed, 28 insertions, 0 deletions
diff --git a/src/libcollections/dlist.rs b/src/libcollections/dlist.rs index e3bae4dfa94..3d322729aab 100644 --- a/src/libcollections/dlist.rs +++ b/src/libcollections/dlist.rs @@ -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() diff --git a/src/libcollections/ringbuf.rs b/src/libcollections/ringbuf.rs index 1ce5b41ffb7..0cde7a90e9c 100644 --- a/src/libcollections/ringbuf.rs +++ b/src/libcollections/ringbuf.rs @@ -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); diff --git a/src/libcollections/treemap.rs b/src/libcollections/treemap.rs index 7a4fe0652cd..afb838333f3 100644 --- a/src/libcollections/treemap.rs +++ b/src/libcollections/treemap.rs @@ -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, "{{")); @@ -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, "{{")); |
