diff options
| author | Graydon Hoare <[email protected]> | 2011-04-25 03:58:53 +0000 |
|---|---|---|
| committer | Graydon Hoare <[email protected]> | 2011-04-25 04:12:33 +0000 |
| commit | 5fe21b5af04166e65ef99828c8b5f4ff5783632a (patch) | |
| tree | b75099314a0077a19ddaccfe33f43e1626b53869 /src | |
| parent | Fix LD_LIBRARY_PATH on STAGE0, STAGE1 defs; define STAGE2. (diff) | |
| download | rust-5fe21b5af04166e65ef99828c8b5f4ff5783632a.tar.xz rust-5fe21b5af04166e65ef99828c8b5f4ff5783632a.zip | |
Skip likely-zero initial probe, speed up map.rs.
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/map.rs | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/lib/map.rs b/src/lib/map.rs index 6c7c0363..4ab2f076 100644 --- a/src/lib/map.rs +++ b/src/lib/map.rs @@ -36,26 +36,26 @@ fn mk_hashmap[K, V](&hashfn[K] hasher, &eqfn[K] eqer) -> hashmap[K, V] { // half and lower half of the uint bits. Our bucket probing // sequence is then defined by // - // hash(key, i) := hashl(key) + i * hashr(key) for i = 0, 1, 2, ... + // hash(key, i) := hashl(key) * i + hashr(key) for i = 0, 1, 2, ... // // Tearing the hash function apart this way is kosher in practice // as, assuming 32-bit uints, the table would have to be at 2^32 // buckets before the resulting pair of hash functions no longer - // probes all buckets for a fixed key. Note that hashr is made to + // probes all buckets for a fixed key. Note that hashl is made to // output odd numbers (hence coprime to the number of nbkts, which // is always a power of 2), so that all buckets are probed for a // fixed key. fn hashl(uint n, uint nbkts) -> uint { - ret (n >>> 16u); + ret ((n >>> 16u) * 2u + 1u); } fn hashr(uint n, uint nbkts) -> uint { - ret ((((~ 0u) >>> 16u) & n) * 2u + 1u); + ret (0x0000_ffff_u & n); } fn hash(uint h, uint nbkts, uint i) -> uint { - ret (hashl(h, nbkts) + i * hashr(h, nbkts)) % nbkts; + ret (hashl(h, nbkts) * i + hashr(h, nbkts)) % nbkts; } /** |