Skip to content

Commit 6361577

Browse files
committed
Implement PartialOrd for RingBuf
1 parent 1cfa656 commit 6361577

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/libcollections/ringbuf.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use core::cmp;
1919
use core::default::Default;
2020
use core::fmt;
2121
use core::iter::RandomAccessIterator;
22+
use core::iter;
2223
use std::hash::{Writer, Hash};
2324

2425
use {Deque, Collection, Mutable, MutableSeq};
@@ -451,6 +452,12 @@ impl<A: PartialEq> PartialEq for RingBuf<A> {
451452
}
452453
}
453454

455+
impl<A: PartialOrd> PartialOrd for RingBuf<A> {
456+
fn partial_cmp(&self, other: &RingBuf<A>) -> Option<Ordering> {
457+
iter::order::partial_cmp(self.iter(), other.iter())
458+
}
459+
}
460+
454461
impl<S: Writer, A: Hash<S>> Hash<S> for RingBuf<A> {
455462
fn hash(&self, state: &mut S) {
456463
for elt in self.iter() {
@@ -940,6 +947,19 @@ mod tests {
940947
assert!(hash::hash(&x) == hash::hash(&y));
941948
}
942949

950+
#[test]
951+
fn test_ord() {
952+
let x = RingBuf::new();
953+
let mut y = RingBuf::new();
954+
y.push(1i);
955+
y.push(2);
956+
y.push(3);
957+
assert!(x < y);
958+
assert!(y > x);
959+
assert!(x <= x);
960+
assert!(x >= x);
961+
}
962+
943963
#[test]
944964
fn test_show() {
945965
let ringbuf: RingBuf<int> = range(0i, 10).collect();

0 commit comments

Comments
 (0)