Skip to content

Commit 5fe21b5

Browse files
committed
Skip likely-zero initial probe, speed up map.rs.
1 parent 0cffc58 commit 5fe21b5

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/lib/map.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,26 +36,26 @@ fn mk_hashmap[K, V](&hashfn[K] hasher, &eqfn[K] eqer) -> hashmap[K, V] {
3636
// half and lower half of the uint bits. Our bucket probing
3737
// sequence is then defined by
3838
//
39-
// hash(key, i) := hashl(key) + i * hashr(key) for i = 0, 1, 2, ...
39+
// hash(key, i) := hashl(key) * i + hashr(key) for i = 0, 1, 2, ...
4040
//
4141
// Tearing the hash function apart this way is kosher in practice
4242
// as, assuming 32-bit uints, the table would have to be at 2^32
4343
// buckets before the resulting pair of hash functions no longer
44-
// probes all buckets for a fixed key. Note that hashr is made to
44+
// probes all buckets for a fixed key. Note that hashl is made to
4545
// output odd numbers (hence coprime to the number of nbkts, which
4646
// is always a power of 2), so that all buckets are probed for a
4747
// fixed key.
4848

4949
fn hashl(uint n, uint nbkts) -> uint {
50-
ret (n >>> 16u);
50+
ret ((n >>> 16u) * 2u + 1u);
5151
}
5252

5353
fn hashr(uint n, uint nbkts) -> uint {
54-
ret ((((~ 0u) >>> 16u) & n) * 2u + 1u);
54+
ret (0x0000_ffff_u & n);
5555
}
5656

5757
fn hash(uint h, uint nbkts, uint i) -> uint {
58-
ret (hashl(h, nbkts) + i * hashr(h, nbkts)) % nbkts;
58+
ret (hashl(h, nbkts) * i + hashr(h, nbkts)) % nbkts;
5959
}
6060

6161
/**

0 commit comments

Comments
 (0)