24 #ifndef TSL_ROBIN_GROWTH_POLICY_H 25 #define TSL_ROBIN_GROWTH_POLICY_H 38 #define tsl_rh_assert(expr) assert(expr) 40 #define tsl_rh_assert(expr) (static_cast<void>(0)) 47 #if (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || \ 48 (defined(_MSC_VER) && defined(_CPPUNWIND))) && \ 49 !defined(TSL_NO_EXCEPTIONS) 50 #define TSL_RH_THROW_OR_TERMINATE(ex, msg) throw ex(msg) 53 #define TSL_RH_THROW_OR_TERMINATE(ex, msg) std::terminate() 56 #define TSL_RH_THROW_OR_TERMINATE(ex, msg) \ 58 std::fprintf(stderr, msg); \ 64 #if defined(__GNUC__) || defined(__clang__) 65 #define TSL_RH_LIKELY(exp) (__builtin_expect(!!(exp), true)) 67 #define TSL_RH_LIKELY(exp) (exp) 97 if (min_bucket_count_in_out > 0) {
99 m_mask = min_bucket_count_in_out - 1;
121 return (
m_mask + 1) * GrowthFactor;
130 return (std::numeric_limits<std::size_t>::max() / 2) + 1;
151 for (std::size_t i = 1; i <
sizeof(std::size_t) * CHAR_BIT; i *= 2) {
160 return value != 0 && (value & (value - 1)) == 0;
165 "GrowthFactor must be a power of two >= 2.");
183 if (min_bucket_count_in_out > 0) {
184 m_mod = min_bucket_count_in_out;
199 const double my_next_bucket_count =
201 if (!std::isnormal(my_next_bucket_count)) {
209 return std::size_t(my_next_bucket_count);
219 1.0 * GrowthFactor::num / GrowthFactor::den;
230 static constexpr
const std::array<std::size_t, 40>
PRIMES = {
231 {1ul, 5ul, 17ul, 29ul, 37ul, 53ul,
232 67ul, 79ul, 97ul, 131ul, 193ul, 257ul,
233 389ul, 521ul, 769ul, 1031ul, 1543ul, 2053ul,
234 3079ul, 6151ul, 12289ul, 24593ul, 49157ul, 98317ul,
235 196613ul, 393241ul, 786433ul, 1572869ul, 3145739ul, 6291469ul,
236 12582917ul, 25165843ul, 50331653ul, 100663319ul, 201326611ul, 402653189ul,
237 805306457ul, 1610612741ul, 3221225473ul, 4294967291ul}};
239 template <
unsigned int IPrime>
static constexpr std::size_t
mod(std::size_t hash)
241 return hash %
PRIMES[IPrime];
247 static constexpr
const std::array<std::size_t (*)(std::size_t), 40>
MOD_PRIME = {
248 {&mod<0>, &mod<1>, &mod<2>, &mod<3>, &mod<4>, &mod<5>, &mod<6>, &mod<7>,
249 &mod<8>, &mod<9>, &mod<10>, &mod<11>, &mod<12>, &mod<13>, &mod<14>, &mod<15>,
250 &mod<16>, &mod<17>, &mod<18>, &mod<19>, &mod<20>, &mod<21>, &mod<22>, &mod<23>,
251 &mod<24>, &mod<25>, &mod<26>, &mod<27>, &mod<28>, &mod<29>, &mod<30>, &mod<31>,
252 &mod<32>, &mod<33>, &mod<34>, &mod<35>, &mod<36>, &mod<37>, &mod<38>, &mod<39>}};
295 if (min_bucket_count_in_out > 0) {
296 min_bucket_count_in_out = *it_prime;
299 min_bucket_count_in_out = 0;
325 "The type of m_iprime is not big enough.");
std::size_t bucket_for_hash(std::size_t hash) const noexcept
Definition: robin_growth_policy.h:110
std::size_t next_bucket_count() const
Definition: robin_growth_policy.h:193
std::size_t m_mod
Definition: robin_growth_policy.h:223
std::size_t bucket_for_hash(std::size_t hash) const noexcept
Definition: robin_growth_policy.h:303
static constexpr std::size_t mod(std::size_t hash)
Definition: robin_growth_policy.h:239
void clear() noexcept
Definition: robin_growth_policy.h:215
Definition: hopscotch_growth_policy.h:37
static constexpr const std::array< std::size_t(*)(std::size_t), 40 > MOD_PRIME
Definition: robin_growth_policy.h:247
std::size_t max_bucket_count() const
Definition: robin_growth_policy.h:317
static const std::size_t MAX_BUCKET_COUNT
Definition: robin_growth_policy.h:220
mod_growth_policy(std::size_t &min_bucket_count_in_out)
Definition: robin_growth_policy.h:177
void clear() noexcept
Definition: robin_growth_policy.h:137
std::size_t max_bucket_count() const
Definition: robin_growth_policy.h:127
std::size_t next_bucket_count() const
Definition: robin_growth_policy.h:308
Definition: robin_growth_policy.h:174
static constexpr const std::array< std::size_t, 40 > PRIMES
Definition: robin_growth_policy.h:230
std::size_t m_mask
Definition: robin_growth_policy.h:165
void clear() noexcept
Definition: robin_growth_policy.h:319
prime_growth_policy(std::size_t &min_bucket_count_in_out)
Definition: robin_growth_policy.h:286
static constexpr bool is_power_of_two(std::size_t value)
Definition: robin_growth_policy.h:158
#define TSL_RH_THROW_OR_TERMINATE(ex, msg)
Definition: robin_growth_policy.h:56
static constexpr double REHASH_SIZE_MULTIPLICATION_FACTOR
Definition: robin_growth_policy.h:218
power_of_two_growth_policy(std::size_t &min_bucket_count_in_out)
Definition: robin_growth_policy.h:91
std::size_t max_bucket_count() const
Definition: robin_growth_policy.h:213
static std::size_t round_up_to_power_of_two(std::size_t value)
Definition: robin_growth_policy.h:140
Definition: robin_growth_policy.h:283
std::size_t next_bucket_count() const
Definition: robin_growth_policy.h:115
unsigned int m_iprime
Definition: robin_growth_policy.h:322
std::size_t bucket_for_hash(std::size_t hash) const noexcept
Definition: robin_growth_policy.h:191
Definition: robin_growth_policy.h:80