collections: Implement Ord for DList, RingBuf, TreeMap, TreeSet

This commit is contained in:
nham 2014-08-01 16:22:48 -04:00
parent 25acfde398
commit 3737c537c3
3 changed files with 28 additions and 0 deletions

View File

@ -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()

View File

@ -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);

View File

@ -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, "{{"));