File tree 1 file changed +29
-0
lines changed
1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -29,6 +29,7 @@ use core::fmt;
29
29
use core:: iter;
30
30
use core:: mem;
31
31
use core:: ptr;
32
+ use std:: hash:: { Writer , Hash } ;
32
33
33
34
use { Collection , Mutable , Deque , MutableSeq } ;
34
35
@@ -707,10 +708,20 @@ impl<A: fmt::Show> fmt::Show for DList<A> {
707
708
}
708
709
}
709
710
711
+ impl < S : Writer , A : Hash < S > > Hash < S > for DList < A > {
712
+ fn hash ( & self , state : & mut S ) {
713
+ self . len ( ) . hash ( state) ;
714
+ for elt in self . iter ( ) {
715
+ elt. hash ( state) ;
716
+ }
717
+ }
718
+ }
719
+
710
720
#[ cfg( test) ]
711
721
mod tests {
712
722
use std:: prelude:: * ;
713
723
use std:: rand;
724
+ use std:: hash;
714
725
use test:: Bencher ;
715
726
use test;
716
727
@@ -1075,6 +1086,24 @@ mod tests {
1075
1086
assert ! ( n != m) ;
1076
1087
}
1077
1088
1089
+ #[ test]
1090
+ fn test_hash ( ) {
1091
+ let mut x = DList :: new ( ) ;
1092
+ let mut y = DList :: new ( ) ;
1093
+
1094
+ assert ! ( hash:: hash( & x) == hash:: hash( & y) ) ;
1095
+
1096
+ x. push_back ( 1 i) ;
1097
+ x. push_back ( 2 ) ;
1098
+ x. push_back ( 3 ) ;
1099
+
1100
+ y. push_front ( 3 i) ;
1101
+ y. push_front ( 2 ) ;
1102
+ y. push_front ( 1 ) ;
1103
+
1104
+ assert ! ( hash:: hash( & x) == hash:: hash( & y) ) ;
1105
+ }
1106
+
1078
1107
#[ test]
1079
1108
fn test_ord ( ) {
1080
1109
let n: DList < int > = list_from ( [ ] ) ;
You can’t perform that action at this time.
0 commit comments