Skip to content

Commit 612c2be

Browse files
JaroslavRybaTessil
authored andcommitted
Fix load threshold on deserialization
The current version computes load using max_load_factor() without first setting m_bucket_count (default 0) leading to threshold 0, which triggers rehash (and size increase) on first insert. Recompute the threshold after setting correct bucket count to avoid this.
1 parent fe845fd commit 612c2be

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

include/tsl/robin_hash.h

+3
Original file line numberDiff line numberDiff line change
@@ -1468,6 +1468,9 @@ class robin_hash : private Hash, private KeyEqual, private GrowthPolicy {
14681468
} else {
14691469
m_bucket_count = numeric_cast<size_type>(
14701470
bucket_count_ds, "Deserialized bucket_count is too big.");
1471+
// Recompute m_load_threshold, during max_load_factor() the bucket count
1472+
// was still 0 which would trigger rehash on first insert
1473+
m_load_threshold = size_type(float(bucket_count()) * m_max_load_factor);
14711474

14721475
GrowthPolicy::operator=(GrowthPolicy(m_bucket_count));
14731476
// GrowthPolicy should not modify the bucket count we got from

0 commit comments

Comments
 (0)