@@ -19,6 +19,8 @@ use core::cmp;
19
19
use core:: default:: Default ;
20
20
use core:: fmt;
21
21
use core:: iter:: RandomAccessIterator ;
22
+ use core:: iter;
23
+ use std:: hash:: { Writer , Hash } ;
22
24
23
25
use { Deque , Collection , Mutable , MutableSeq } ;
24
26
use vec:: Vec ;
@@ -450,6 +452,21 @@ impl<A: PartialEq> PartialEq for RingBuf<A> {
450
452
}
451
453
}
452
454
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
+
461
+ impl < S : Writer , A : Hash < S > > Hash < S > for RingBuf < A > {
462
+ fn hash ( & self , state : & mut S ) {
463
+ self . len ( ) . hash ( state) ;
464
+ for elt in self . iter ( ) {
465
+ elt. hash ( state) ;
466
+ }
467
+ }
468
+ }
469
+
453
470
impl < A > FromIterator < A > for RingBuf < A > {
454
471
fn from_iter < T : Iterator < A > > ( iterator : T ) -> RingBuf < A > {
455
472
let ( lower, _) = iterator. size_hint ( ) ;
@@ -485,6 +502,7 @@ mod tests {
485
502
use std:: fmt:: Show ;
486
503
use std:: prelude:: * ;
487
504
use std:: gc:: { GC , Gc } ;
505
+ use std:: hash;
488
506
use test:: Bencher ;
489
507
use test;
490
508
@@ -912,6 +930,37 @@ mod tests {
912
930
assert ! ( e == RingBuf :: new( ) ) ;
913
931
}
914
932
933
+ #[ test]
934
+ fn test_hash ( ) {
935
+ let mut x = RingBuf :: new ( ) ;
936
+ let mut y = RingBuf :: new ( ) ;
937
+
938
+ x. push ( 1 i) ;
939
+ x. push ( 2 ) ;
940
+ x. push ( 3 ) ;
941
+
942
+ y. push ( 0 i) ;
943
+ y. push ( 1 i) ;
944
+ y. pop_front ( ) ;
945
+ y. push ( 2 ) ;
946
+ y. push ( 3 ) ;
947
+
948
+ assert ! ( hash:: hash( & x) == hash:: hash( & y) ) ;
949
+ }
950
+
951
+ #[ test]
952
+ fn test_ord ( ) {
953
+ let x = RingBuf :: new ( ) ;
954
+ let mut y = RingBuf :: new ( ) ;
955
+ y. push ( 1 i) ;
956
+ y. push ( 2 ) ;
957
+ y. push ( 3 ) ;
958
+ assert ! ( x < y) ;
959
+ assert ! ( y > x) ;
960
+ assert ! ( x <= x) ;
961
+ assert ! ( x >= x) ;
962
+ }
963
+
915
964
#[ test]
916
965
fn test_show ( ) {
917
966
let ringbuf: RingBuf < int > = range ( 0 i, 10 ) . collect ( ) ;
0 commit comments