From 51a2c434bc43be21cbcdc58982f88095fcaa3f01 Mon Sep 17 00:00:00 2001 From: joaquintides Date: Sat, 29 Oct 2022 12:33:19 +0200 Subject: [PATCH] adjusted hysteresis factor in unchecked_emplace_with_rehash --- include/boost/unordered/detail/foa.hpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/include/boost/unordered/detail/foa.hpp b/include/boost/unordered/detail/foa.hpp index 3e30a000..d1359a04 100644 --- a/include/boost/unordered/detail/foa.hpp +++ b/include/boost/unordered/detail/foa.hpp @@ -1654,11 +1654,15 @@ private: /* Due to the anti-drift mechanism (see recover_slot), new_arrays_ may be * of the same size as the old arrays; in the limit, erasing one element at * full load and then inserting could bring us back to the same capacity - * after a costly rehash. We introduce a 10% level of hysteresis to avoid - * that (the size_/10 addendum). + * after a costly rehash. To avoid this, we jump to the next capacity level + * when the number of erased elements is <= 10% of total elements at full + * load, which is implemented by requesting additional F*size elements, + * with F = P * 10% / (1 - P * 10%), where P is the probability of an + * element having caused overflow; P has been determined to be ~0.187 via + * simulation, yielding F ~ 0.019 ~ 1/52. */ auto new_arrays_=new_arrays(std::size_t( - std::ceil(static_cast(size_+size_/10+1)/mlf))); + std::ceil(static_cast(size_+size_/52+1)/mlf))); iterator it; BOOST_TRY{ /* strong exception guarantee -> try insertion before rehash */