File tree 1 file changed +18
-0
lines changed
1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -40,6 +40,24 @@ const LOAD_FACTOR_THRESHOLD: f32 = 0.625;
40
40
// low (~ 20%). We choose 62.5%, because it's a simple fraction (5/8), and its half is 31.25%.
41
41
// (When a map is grown, the load factor is halved.)
42
42
43
+ // At a load factor of α, the odds of finding the target bucket after exactly n
44
+ // unsuccesful probes[1] are
45
+ //
46
+ // Pr_α{displacement = n} =
47
+ // (1 - α) / α * ∑_{k≥1} e^(-kα) * (kα)^(k+n) / (k + n)! * (1 - kα / (k + n + 1))
48
+ //
49
+ // We use this formula to find the probability of loading half of a cache line, as well as
50
+ // the probability of triggering the DoS safeguard with an insertion:
51
+ //
52
+ // Pr_0.625{displacement > 3} = 0.036
53
+ // Pr_0.625{displacement > 128} = 2.284 * 10^-49
54
+
55
+ // Pr_0.909{displacement > 3} = 0.487
56
+ // Pr_0.909{displacement > 128} = 1.601 * 10^-11
57
+ //
58
+ // 1. Alfredo Viola (2005). Distributional analysis of Robin Hood linear probing
59
+ // hashing with buckets.
60
+
43
61
// TODO: add one-shot hashing for String, str, arrays and other types.
44
62
// TODO: consider adding a limit for the number of fully equal hashes in a probe sequence.
45
63
// Fully equal hashes cause key comparison, which might be a problem for large string keys.
You can’t perform that action at this time.
0 commit comments