// is always a power? of 2), so that all buckets are probed for a
// fixed key.
- fn hashl(n: u32) -> u32 { ret (n >>> 16u32) * 2u32 + 1u32; }
- fn hashr(n: u32) -> u32 { ret 0x0000_ffff_u32 & n; }
- fn hash(h: u32, nbkts: uint, i: uint) -> uint {
- ret ((hashl(h) as uint) * i + (hashr(h) as uint)) % nbkts;
- }
-
- fn to_u64(h: uint) -> u32 {
- ret (h as u32) ^ ((h >>> 16u) as u32);
+ fn hashl(n: uint) -> uint { ret (n >>> 16u) * 2u + 1u; }
+ fn hashr(n: uint) -> uint { ret 0x0000_ffff_u & n; }
+ fn hash(h: uint, nbkts: uint, i: uint) -> uint {
+ ret (hashl(h) * i + hashr(h)) % nbkts;
}
/**
bkts: [mutable bucket<K, V>],
nbkts: uint, key: K, val: V) -> bool {
let i: uint = 0u;
- let h = to_u64(hasher(key));
+ let h = hasher(key);
while i < nbkts {
let j: uint = hash(h, nbkts, i);
alt bkts[j] {
// Copy key to please alias analysis.
let k_ = k;
- if eqer(key, k_) { bkts[j] = some(k_, val); ret false; }
+ if eqer(key, k_) {
+ log("map updated", "i", i, "h", h, "nbkts", nbkts);
+ bkts[j] = some(k_, val);
+ ret false;
+ }
i += 1u;
}
- _ { bkts[j] = some(key, val); ret true; }
+ _ {
+ log("map inserted", "i", i, "h", h, "nbkts", nbkts);
+ bkts[j] = some(key, val);
+ ret true;
+ }
}
}
fail; // full table
bkts: [mutable bucket<K, V>],
nbkts: uint, key: K) -> option::t<V> {
let i: uint = 0u;
- let h = to_u64(hasher(key));
+ let h = hasher(key);
while i < nbkts {
let j: uint = hash(h, nbkts, i);
alt bkts[j] {
// Copy to please alias analysis.
let k_ = k;
let v_ = v;
- if eqer(key, k_) { ret option::some(v_); }
+ if eqer(key, k_) {
+ log("map present", "i", i, "h", h, "nbkts", nbkts);
+ ret option::some(v_);
+ }
+ }
+ nil. {
+ log("map absent", "i", i, "h", h, "nbkts", nbkts);
+ ret option::none;
}
- nil. { ret option::none; }
deleted. { }
}
i += 1u;
}
fn remove(key: K) -> option::t<V> {
let i: uint = 0u;
- let h = to_u64(hasher(key));
+ let h = hasher(key);
while i < nbkts {
let j: uint = hash(h, nbkts, i);
alt bkts[j] {