@@ -36,26 +36,26 @@ fn mk_hashmap[K, V](&hashfn[K] hasher, &eqfn[K] eqer) -> hashmap[K, V] {
36
36
// half and lower half of the uint bits. Our bucket probing
37
37
// sequence is then defined by
38
38
//
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, ...
40
40
//
41
41
// Tearing the hash function apart this way is kosher in practice
42
42
// as, assuming 32-bit uints, the table would have to be at 2^32
43
43
// 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
45
45
// output odd numbers (hence coprime to the number of nbkts, which
46
46
// is always a power of 2), so that all buckets are probed for a
47
47
// fixed key.
48
48
49
49
fn hashl ( uint n, uint nbkts ) -> uint {
50
- ret ( n >>> 16 u) ;
50
+ ret ( ( n >>> 16 u) * 2 u + 1 u ) ;
51
51
}
52
52
53
53
fn hashr ( uint n, uint nbkts ) -> uint {
54
- ret ( ( ( ( ~ 0 u ) >>> 16 u ) & n) * 2 u + 1 u ) ;
54
+ ret ( 0x0000_ffff_ u & n) ;
55
55
}
56
56
57
57
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;
59
59
}
60
60
61
61
/**
0 commit comments