File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Expand file tree Collapse file tree 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;
4040// low (~ 20%). We choose 62.5%, because it's a simple fraction (5/8), and its half is 31.25%.
4141// (When a map is grown, the load factor is halved.)
4242
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+
4361// TODO: add one-shot hashing for String, str, arrays and other types.
4462// TODO: consider adding a limit for the number of fully equal hashes in a probe sequence.
4563// 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