@@ -24,6 +24,8 @@ use core::mem::replace;
2424use { Collection , Mutable , Map , MutableMap , MutableSeq } ;
2525use { vec, slice} ;
2626use vec:: Vec ;
27+ use hash;
28+ use hash:: Hash ;
2729
2830/// A map optimized for small integer keys.
2931///
@@ -58,7 +60,7 @@ use vec::Vec;
5860/// months.clear();
5961/// assert!(months.is_empty());
6062/// ```
61- #[ deriving( Hash , PartialEq , Eq ) ]
63+ #[ deriving( PartialEq , Eq ) ]
6264pub struct SmallIntMap < T > {
6365 v : Vec < Option < T > > ,
6466}
@@ -167,6 +169,12 @@ impl<V:Clone> Clone for SmallIntMap<V> {
167169 }
168170}
169171
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+
170178impl < V > SmallIntMap < V > {
171179 /// Create an empty SmallIntMap.
172180 ///
@@ -478,8 +486,8 @@ pub type Values<'a, T> =
478486#[ cfg( test) ]
479487mod test_map {
480488 use std:: prelude:: * ;
481- use std:: hash;
482489 use vec:: Vec ;
490+ use hash;
483491
484492 use { Map , MutableMap , Mutable , MutableSeq } ;
485493 use super :: SmallIntMap ;
@@ -764,19 +772,19 @@ mod test_map {
764772
765773 #[ test]
766774 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 ( ) ;
769777
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' ) ;
774782
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' ) ;
778786
779- assert ! ( hash:: hash( & x) == hash:: hash( & y) ) ;
787+ assert ! ( hash:: hash( & x) == hash:: hash( & y) ) ;
780788 }
781789
782790 #[ test]
0 commit comments