@@ -24,6 +24,8 @@ use core::mem::replace;
24
24
use { Collection , Mutable , Map , MutableMap , MutableSeq } ;
25
25
use { vec, slice} ;
26
26
use vec:: Vec ;
27
+ use hash;
28
+ use hash:: Hash ;
27
29
28
30
/// A map optimized for small integer keys.
29
31
///
@@ -58,7 +60,7 @@ use vec::Vec;
58
60
/// months.clear();
59
61
/// assert!(months.is_empty());
60
62
/// ```
61
- #[ deriving( Hash , PartialEq , Eq ) ]
63
+ #[ deriving( PartialEq , Eq ) ]
62
64
pub struct SmallIntMap < T > {
63
65
v : Vec < Option < T > > ,
64
66
}
@@ -167,6 +169,12 @@ impl<V:Clone> Clone for SmallIntMap<V> {
167
169
}
168
170
}
169
171
172
+ impl < S : hash:: Writer , T : Hash < S > > Hash < S > for SmallIntMap < T > {
173
+ fn hash ( & self , state : & mut S ) {
174
+ self . v . hash ( state)
175
+ }
176
+ }
177
+
170
178
impl < V > SmallIntMap < V > {
171
179
/// Create an empty SmallIntMap.
172
180
///
@@ -478,8 +486,8 @@ pub type Values<'a, T> =
478
486
#[ cfg( test) ]
479
487
mod test_map {
480
488
use std:: prelude:: * ;
481
- use std:: hash;
482
489
use vec:: Vec ;
490
+ use hash;
483
491
484
492
use { Map , MutableMap , Mutable , MutableSeq } ;
485
493
use super :: SmallIntMap ;
@@ -764,19 +772,19 @@ mod test_map {
764
772
765
773
#[ test]
766
774
fn test_hash ( ) {
767
- let mut x = SmallIntMap :: new ( ) ;
768
- let mut y = SmallIntMap :: new ( ) ;
775
+ let mut x = SmallIntMap :: new ( ) ;
776
+ let mut y = SmallIntMap :: new ( ) ;
769
777
770
- assert ! ( hash:: hash( & x) == hash:: hash( & y) ) ;
771
- x. insert ( 1 , 'a' ) ;
772
- x. insert ( 2 , 'b' ) ;
773
- x. insert ( 3 , 'c' ) ;
778
+ assert ! ( hash:: hash( & x) == hash:: hash( & y) ) ;
779
+ x. insert ( 1 , 'a' ) ;
780
+ x. insert ( 2 , 'b' ) ;
781
+ x. insert ( 3 , 'c' ) ;
774
782
775
- y. insert ( 3 , 'c' ) ;
776
- y. insert ( 2 , 'b' ) ;
777
- y. insert ( 1 , 'a' ) ;
783
+ y. insert ( 3 , 'c' ) ;
784
+ y. insert ( 2 , 'b' ) ;
785
+ y. insert ( 1 , 'a' ) ;
778
786
779
- assert ! ( hash:: hash( & x) == hash:: hash( & y) ) ;
787
+ assert ! ( hash:: hash( & x) == hash:: hash( & y) ) ;
780
788
}
781
789
782
790
#[ test]
0 commit comments