diff --git a/include/tsl/robin_hash.h b/include/tsl/robin_hash.h index 8299795..5fdc07f 100644 --- a/include/tsl/robin_hash.h +++ b/include/tsl/robin_hash.h @@ -1231,7 +1231,7 @@ class robin_hash : private Hash, private KeyEqual, private GrowthPolicy { dist_from_ideal_bucket++; } - if (rehash_on_extreme_load()) { + while (rehash_on_extreme_load(dist_from_ideal_bucket)) { ibucket = bucket_for_hash(hash); dist_from_ideal_bucket = 0; @@ -1293,7 +1293,7 @@ class robin_hash : private Hash, private KeyEqual, private GrowthPolicy { while (!m_buckets[ibucket].empty()) { if (dist_from_ideal_bucket > m_buckets[ibucket].dist_from_ideal_bucket()) { - if (dist_from_ideal_bucket >= + if (dist_from_ideal_bucket > bucket_entry::DIST_FROM_IDEAL_BUCKET_LIMIT) { /** * The number of probes is really high, rehash the map on the next @@ -1379,8 +1379,11 @@ class robin_hash : private Hash, private KeyEqual, private GrowthPolicy { * * Return true if the table has been rehashed. */ - bool rehash_on_extreme_load() { - if (m_grow_on_next_insert || size() >= m_load_threshold) { + bool rehash_on_extreme_load(distance_type curr_dist_from_ideal_bucket) { + if (m_grow_on_next_insert || + curr_dist_from_ideal_bucket > + bucket_entry::DIST_FROM_IDEAL_BUCKET_LIMIT || + size() >= m_load_threshold) { rehash_impl(GrowthPolicy::next_bucket_count()); m_grow_on_next_insert = false;