mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
collections: Implement Ord for DList, RingBuf, TreeMap, TreeSet
This commit is contained in:
parent
25acfde398
commit
3737c537c3
@ -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()
|
||||
|
@ -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);
|
||||
|
@ -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, "{{"));
|
||||
|
Loading…
Reference in New Issue
Block a user