Skip to content

Commit

Permalink
Fix USE_STORED_HASH_ON_REHASH to return true when bucket_count is 0, …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
Tessil committed Feb 27, 2022
1 parent a603419 commit a24e904
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 3 additions & 3 deletions include/tsl/robin_hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -410,9 +410,9 @@ class robin_hash : private Hash, private KeyEqual, private GrowthPolicy {
TSL_RH_UNUSED(bucket_count);
return true;
} else if (STORE_HASH && is_power_of_two_policy<GrowthPolicy>::value) {
tsl_rh_assert(bucket_count > 0);
return (bucket_count - 1) <=
std::numeric_limits<truncated_hash_type>::max();
return bucket_count == 0 ||
(bucket_count - 1) <=
std::numeric_limits<truncated_hash_type>::max();
} else {
TSL_RH_UNUSED(bucket_count);
return false;
Expand Down
8 changes: 8 additions & 0 deletions tests/robin_map_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,14 @@ BOOST_AUTO_TEST_CASE(test_range_insert) {
}
}

BOOST_AUTO_TEST_CASE(test_rehash_0) {
tsl::robin_map<int, int, std::hash<int>,
std::equal_to<int>,
std::allocator<std::pair<int, int>>,
true> map;
map.rehash(0);
}

BOOST_AUTO_TEST_CASE(test_insert_with_hint) {
tsl::robin_map<int, int> map{{1, 0}, {2, 1}, {3, 2}};

Expand Down

0 comments on commit a24e904

Please sign in to comment.