@@ -137,21 +137,25 @@ fn mk_hashmap<copy K, copy V>(hasher: hashfn<K>, eqer: eqfn<K>)
137
137
// is always a power of 2), so that all buckets are probed for a
138
138
// fixed key.
139
139
140
- fn hashl ( n : uint , _nbkts : uint ) -> uint { ret ( n >>> 16 u ) * 2 u + 1 u ; }
141
- fn hashr ( n : uint , _nbkts : uint ) -> uint { ret 0x0000_ffff_ u & n; }
142
- fn hash ( h : uint , nbkts : uint , i : uint ) -> uint {
143
- ret ( hashl ( h, nbkts ) * i + hashr ( h, nbkts ) ) % nbkts;
140
+ fn hashl ( n : u32 ) -> u32 { ret ( n >>> 16u32 ) * 2u32 + 1u32 ; }
141
+ fn hashr ( n : u32 ) -> u32 { ret 0x0000_ffff_u32 & n; }
142
+ fn hash ( h : u32 , nbkts : uint , i : uint ) -> uint {
143
+ ret ( ( hashl ( h) as uint ) * i + ( hashr ( h) as uint ) ) % nbkts;
144
144
}
145
+
146
+ fn to_u64 ( h : uint ) -> u32 {
147
+ ret ( h as u32 ) ^ ( ( h >>> 16 u) as u32 ) ;
148
+ }
149
+
145
150
/**
146
151
* We attempt to never call this with a full table. If we do, it
147
152
* will fail.
148
153
*/
149
-
150
154
fn insert_common < copy K , copy V > ( hasher : hashfn < K > , eqer : eqfn < K > ,
151
155
bkts : [ mutable bucket< K , V > ] ,
152
156
nbkts : uint , key : K , val : V ) -> bool {
153
157
let i: uint = 0 u;
154
- let h: uint = hasher ( key) ;
158
+ let h = to_u64 ( hasher ( key) ) ;
155
159
while i < nbkts {
156
160
let j: uint = hash ( h, nbkts, i) ;
157
161
alt bkts[ j] {
@@ -171,7 +175,7 @@ fn mk_hashmap<copy K, copy V>(hasher: hashfn<K>, eqer: eqfn<K>)
171
175
bkts : [ mutable bucket< K , V > ] ,
172
176
nbkts : uint , key : K ) -> option:: t < V > {
173
177
let i: uint = 0 u;
174
- let h: uint = hasher ( key) ;
178
+ let h = to_u64 ( hasher ( key) ) ;
175
179
while i < nbkts {
176
180
let j: uint = hash ( h, nbkts, i) ;
177
181
alt bkts[ j] {
@@ -244,7 +248,7 @@ fn mk_hashmap<copy K, copy V>(hasher: hashfn<K>, eqer: eqfn<K>)
244
248
}
245
249
fn remove ( key : K ) -> option:: t < V > {
246
250
let i: uint = 0 u;
247
- let h: uint = hasher ( key) ;
251
+ let h = to_u64 ( hasher ( key) ) ;
248
252
while i < nbkts {
249
253
let j: uint = hash ( h, nbkts, i) ;
250
254
alt bkts[ j] {
0 commit comments