Skip to content

Commit f32d1d3

Browse files
committed
---
yaml --- r: 6597 b: refs/heads/master c: 6635560 h: refs/heads/master i: 6595: 32e6a4d v: v3
1 parent 49fe95c commit f32d1d3

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: aa99bfa170971b14bb72a10ef153480ec4caaa46
2+
refs/heads/master: 66355607da4a2491e4a75dc6e0d2036120f0ede2

trunk/src/libstd/map.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -137,21 +137,25 @@ fn mk_hashmap<copy K, copy V>(hasher: hashfn<K>, eqer: eqfn<K>)
137137
// is always a power of 2), so that all buckets are probed for a
138138
// fixed key.
139139

140-
fn hashl(n: uint, _nbkts: uint) -> uint { ret (n >>> 16u) * 2u + 1u; }
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;
144144
}
145+
146+
fn to_u64(h: uint) -> u32 {
147+
ret (h as u32) ^ ((h >>> 16u) as u32);
148+
}
149+
145150
/**
146151
* We attempt to never call this with a full table. If we do, it
147152
* will fail.
148153
*/
149-
150154
fn insert_common<copy K, copy V>(hasher: hashfn<K>, eqer: eqfn<K>,
151155
bkts: [mutable bucket<K, V>],
152156
nbkts: uint, key: K, val: V) -> bool {
153157
let i: uint = 0u;
154-
let h: uint = hasher(key);
158+
let h = to_u64(hasher(key));
155159
while i < nbkts {
156160
let j: uint = hash(h, nbkts, i);
157161
alt bkts[j] {
@@ -171,7 +175,7 @@ fn mk_hashmap<copy K, copy V>(hasher: hashfn<K>, eqer: eqfn<K>)
171175
bkts: [mutable bucket<K, V>],
172176
nbkts: uint, key: K) -> option::t<V> {
173177
let i: uint = 0u;
174-
let h: uint = hasher(key);
178+
let h = to_u64(hasher(key));
175179
while i < nbkts {
176180
let j: uint = hash(h, nbkts, i);
177181
alt bkts[j] {
@@ -244,7 +248,7 @@ fn mk_hashmap<copy K, copy V>(hasher: hashfn<K>, eqer: eqfn<K>)
244248
}
245249
fn remove(key: K) -> option::t<V> {
246250
let i: uint = 0u;
247-
let h: uint = hasher(key);
251+
let h = to_u64(hasher(key));
248252
while i < nbkts {
249253
let j: uint = hash(h, nbkts, i);
250254
alt bkts[j] {

0 commit comments

Comments
 (0)