Skip to content

Commit 8943b53

Browse files
committed
---
yaml --- r: 6625 b: refs/heads/master c: ed0e13f h: refs/heads/master i: 6623: ac6957c v: v3
1 parent 28409a7 commit 8943b53

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
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: 30a2361e6848827036edae21fec795b958cc1b9d
2+
refs/heads/master: ed0e13f1d86124845606fd378f4ab3cec3d1c9b3

trunk/src/libstd/map.rs

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -384,14 +384,10 @@ fn mk_flat_hashmap<copy K, copy V>(hasher: hashfn<K>, eqer: eqfn<K>)
384384
// is always a power? of 2), so that all buckets are probed for a
385385
// fixed key.
386386

387-
fn hashl(n: u32) -> u32 { ret (n >>> 16u32) * 2u32 + 1u32; }
388-
fn hashr(n: u32) -> u32 { ret 0x0000_ffff_u32 & n; }
389-
fn hash(h: u32, nbkts: uint, i: uint) -> uint {
390-
ret ((hashl(h) as uint) * i + (hashr(h) as uint)) % nbkts;
391-
}
392-
393-
fn to_u64(h: uint) -> u32 {
394-
ret (h as u32) ^ ((h >>> 16u) as u32);
387+
fn hashl(n: uint) -> uint { ret (n >>> 16u) * 2u + 1u; }
388+
fn hashr(n: uint) -> uint { ret 0x0000_ffff_u & n; }
389+
fn hash(h: uint, nbkts: uint, i: uint) -> uint {
390+
ret (hashl(h) * i + hashr(h)) % nbkts;
395391
}
396392

397393
/**
@@ -402,18 +398,26 @@ fn mk_flat_hashmap<copy K, copy V>(hasher: hashfn<K>, eqer: eqfn<K>)
402398
bkts: [mutable bucket<K, V>],
403399
nbkts: uint, key: K, val: V) -> bool {
404400
let i: uint = 0u;
405-
let h = to_u64(hasher(key));
401+
let h = hasher(key);
406402
while i < nbkts {
407403
let j: uint = hash(h, nbkts, i);
408404
alt bkts[j] {
409405
some(k, _) {
410406
// Copy key to please alias analysis.
411407

412408
let k_ = k;
413-
if eqer(key, k_) { bkts[j] = some(k_, val); ret false; }
409+
if eqer(key, k_) {
410+
log("map updated", "i", i, "h", h, "nbkts", nbkts);
411+
bkts[j] = some(k_, val);
412+
ret false;
413+
}
414414
i += 1u;
415415
}
416-
_ { bkts[j] = some(key, val); ret true; }
416+
_ {
417+
log("map inserted", "i", i, "h", h, "nbkts", nbkts);
418+
bkts[j] = some(key, val);
419+
ret true;
420+
}
417421
}
418422
}
419423
fail; // full table
@@ -422,17 +426,23 @@ fn mk_flat_hashmap<copy K, copy V>(hasher: hashfn<K>, eqer: eqfn<K>)
422426
bkts: [mutable bucket<K, V>],
423427
nbkts: uint, key: K) -> option::t<V> {
424428
let i: uint = 0u;
425-
let h = to_u64(hasher(key));
429+
let h = hasher(key);
426430
while i < nbkts {
427431
let j: uint = hash(h, nbkts, i);
428432
alt bkts[j] {
429433
some(k, v) {
430434
// Copy to please alias analysis.
431435
let k_ = k;
432436
let v_ = v;
433-
if eqer(key, k_) { ret option::some(v_); }
437+
if eqer(key, k_) {
438+
log("map present", "i", i, "h", h, "nbkts", nbkts);
439+
ret option::some(v_);
440+
}
441+
}
442+
nil. {
443+
log("map absent", "i", i, "h", h, "nbkts", nbkts);
444+
ret option::none;
434445
}
435-
nil. { ret option::none; }
436446
deleted. { }
437447
}
438448
i += 1u;
@@ -495,7 +505,7 @@ fn mk_flat_hashmap<copy K, copy V>(hasher: hashfn<K>, eqer: eqfn<K>)
495505
}
496506
fn remove(key: K) -> option::t<V> {
497507
let i: uint = 0u;
498-
let h = to_u64(hasher(key));
508+
let h = hasher(key);
499509
while i < nbkts {
500510
let j: uint = hash(h, nbkts, i);
501511
alt bkts[j] {

0 commit comments

Comments
 (0)