File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ use core::cmp;
19
19
use core:: default:: Default ;
20
20
use core:: fmt;
21
21
use core:: iter:: RandomAccessIterator ;
22
+ use std:: hash:: { Writer , Hash } ;
22
23
23
24
use { Deque , Collection , Mutable , MutableSeq } ;
24
25
use vec:: Vec ;
@@ -450,6 +451,14 @@ impl<A: PartialEq> PartialEq for RingBuf<A> {
450
451
}
451
452
}
452
453
454
+ impl < S : Writer , A : Hash < S > > Hash < S > for RingBuf < A > {
455
+ fn hash ( & self , state : & mut S ) {
456
+ for elt in self . iter ( ) {
457
+ elt. hash ( state) ;
458
+ }
459
+ }
460
+ }
461
+
453
462
impl < A > FromIterator < A > for RingBuf < A > {
454
463
fn from_iter < T : Iterator < A > > ( iterator : T ) -> RingBuf < A > {
455
464
let ( lower, _) = iterator. size_hint ( ) ;
@@ -485,6 +494,7 @@ mod tests {
485
494
use std:: fmt:: Show ;
486
495
use std:: prelude:: * ;
487
496
use std:: gc:: { GC , Gc } ;
497
+ use std:: hash;
488
498
use test:: Bencher ;
489
499
use test;
490
500
@@ -912,6 +922,24 @@ mod tests {
912
922
assert ! ( e == RingBuf :: new( ) ) ;
913
923
}
914
924
925
+ #[ test]
926
+ fn test_hash ( ) {
927
+ let mut x = RingBuf :: new ( ) ;
928
+ let mut y = RingBuf :: new ( ) ;
929
+
930
+ x. push ( 1 i) ;
931
+ x. push ( 2 ) ;
932
+ x. push ( 3 ) ;
933
+
934
+ y. push ( 0 i) ;
935
+ y. push ( 1 i) ;
936
+ y. pop_front ( ) ;
937
+ y. push ( 2 ) ;
938
+ y. push ( 3 ) ;
939
+
940
+ assert ! ( hash:: hash( & x) == hash:: hash( & y) ) ;
941
+ }
942
+
915
943
#[ test]
916
944
fn test_show ( ) {
917
945
let ringbuf: RingBuf < int > = range ( 0 i, 10 ) . collect ( ) ;
You can’t perform that action at this time.
0 commit comments