From a24e904455aa0bf09f9c7dc4f740ffe00f220907 Mon Sep 17 00:00:00 2001 From: Tessil Date: Sun, 27 Feb 2022 15:56:13 +0000 Subject: [PATCH] Fix USE_STORED_HASH_ON_REHASH to return true when bucket_count is 0, STORE_HASH is true and is_power_of_two_policy::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. --- include/tsl/robin_hash.h | 6 +++--- tests/robin_map_tests.cpp | 8 ++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/include/tsl/robin_hash.h b/include/tsl/robin_hash.h index e34eac3..98643e6 100644 --- a/include/tsl/robin_hash.h +++ b/include/tsl/robin_hash.h @@ -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::value) { - tsl_rh_assert(bucket_count > 0); - return (bucket_count - 1) <= - std::numeric_limits::max(); + return bucket_count == 0 || + (bucket_count - 1) <= + std::numeric_limits::max(); } else { TSL_RH_UNUSED(bucket_count); return false; diff --git a/tests/robin_map_tests.cpp b/tests/robin_map_tests.cpp index 34cbd26..cfa620e 100644 --- a/tests/robin_map_tests.cpp +++ b/tests/robin_map_tests.cpp @@ -140,6 +140,14 @@ BOOST_AUTO_TEST_CASE(test_range_insert) { } } +BOOST_AUTO_TEST_CASE(test_rehash_0) { + tsl::robin_map, + std::equal_to, + std::allocator>, + true> map; + map.rehash(0); +} + BOOST_AUTO_TEST_CASE(test_insert_with_hint) { tsl::robin_map map{{1, 0}, {2, 1}, {3, 2}};