From 3737c537c3bb1aa96ddfd934fd4c48839249f5eb Mon Sep 17 00:00:00 2001 From: nham Date: Fri, 1 Aug 2014 16:22:48 -0400 Subject: [PATCH] collections: Implement Ord for DList, RingBuf, TreeMap, TreeSet --- src/libcollections/dlist.rs | 7 +++++++ src/libcollections/ringbuf.rs | 7 +++++++ src/libcollections/treemap.rs | 14 ++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/src/libcollections/dlist.rs b/src/libcollections/dlist.rs index e3bae4dfa94c1..3d322729aab43 100644 --- a/src/libcollections/dlist.rs +++ b/src/libcollections/dlist.rs @@ -691,6 +691,13 @@ impl PartialOrd for DList { } } +impl Ord for DList { + #[inline] + fn cmp(&self, other: &DList) -> Ordering { + iter::order::cmp(self.iter(), other.iter()) + } +} + impl Clone for DList { fn clone(&self) -> DList { self.iter().map(|x| x.clone()).collect() diff --git a/src/libcollections/ringbuf.rs b/src/libcollections/ringbuf.rs index 1ce5b41ffb7e9..0cde7a90e9c89 100644 --- a/src/libcollections/ringbuf.rs +++ b/src/libcollections/ringbuf.rs @@ -460,6 +460,13 @@ impl PartialOrd for RingBuf { } } +impl Ord for RingBuf { + #[inline] + fn cmp(&self, other: &RingBuf) -> Ordering { + iter::order::cmp(self.iter(), other.iter()) + } +} + impl> Hash for RingBuf { fn hash(&self, state: &mut S) { self.len().hash(state); diff --git a/src/libcollections/treemap.rs b/src/libcollections/treemap.rs index 7a4fe0652cdab..afb838333f351 100644 --- a/src/libcollections/treemap.rs +++ b/src/libcollections/treemap.rs @@ -182,6 +182,13 @@ impl PartialOrd for TreeMap { } } +impl Ord for TreeMap { + #[inline] + fn cmp(&self, other: &TreeMap) -> Ordering { + iter::order::cmp(self.iter(), other.iter()) + } +} + impl Show for TreeMap { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { try!(write!(f, "{{")); @@ -1021,6 +1028,13 @@ impl PartialOrd for TreeSet { } } +impl Ord for TreeSet { + #[inline] + fn cmp(&self, other: &TreeSet) -> Ordering { + iter::order::cmp(self.iter(), other.iter()) + } +} + impl Show for TreeSet { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { try!(write!(f, "{{"));