about summary refs log tree commit diff
path: root/src/lib
diff options
context:
space:
mode:
authorGraydon Hoare <graydon@mozilla.com>2011-04-25 03:58:53 +0000
committerGraydon Hoare <graydon@mozilla.com>2011-04-25 04:12:33 +0000
commit5fe21b5af04166e65ef99828c8b5f4ff5783632a (patch)
treeb75099314a0077a19ddaccfe33f43e1626b53869 /src/lib
parent0cffc582255dcc45c5097f7e77217cb1509f1c41 (diff)
Skip likely-zero initial probe, speed up map.rs.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/map.rs10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/lib/map.rs b/src/lib/map.rs
index 6c7c0363254..4ab2f076b9c 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;
     }
 
     /**