Skip to content

Commit a24e904

Browse files
committed
Fix USE_STORED_HASH_ON_REHASH to return true when bucket_count is 0, STORE_HASH is true and is_power_of_two_policy<GrowthPolicy>::value is true
This commit doesn't change the actual behaviour of the map as even when USE_STORED_HASH_ON_REHASH was returning false on empty map rehashes, no stored hashes were used as the map was empty.
1 parent a603419 commit a24e904

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

include/tsl/robin_hash.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -410,9 +410,9 @@ class robin_hash : private Hash, private KeyEqual, private GrowthPolicy {
410410
TSL_RH_UNUSED(bucket_count);
411411
return true;
412412
} else if (STORE_HASH && is_power_of_two_policy<GrowthPolicy>::value) {
413-
tsl_rh_assert(bucket_count > 0);
414-
return (bucket_count - 1) <=
415-
std::numeric_limits<truncated_hash_type>::max();
413+
return bucket_count == 0 ||
414+
(bucket_count - 1) <=
415+
std::numeric_limits<truncated_hash_type>::max();
416416
} else {
417417
TSL_RH_UNUSED(bucket_count);
418418
return false;

tests/robin_map_tests.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,14 @@ BOOST_AUTO_TEST_CASE(test_range_insert) {
140140
}
141141
}
142142

143+
BOOST_AUTO_TEST_CASE(test_rehash_0) {
144+
tsl::robin_map<int, int, std::hash<int>,
145+
std::equal_to<int>,
146+
std::allocator<std::pair<int, int>>,
147+
true> map;
148+
map.rehash(0);
149+
}
150+
143151
BOOST_AUTO_TEST_CASE(test_insert_with_hint) {
144152
tsl::robin_map<int, int> map{{1, 0}, {2, 1}, {3, 2}};
145153

0 commit comments

Comments
 (0)