24#ifndef TSL_ROBIN_GROWTH_POLICY_H
25#define TSL_ROBIN_GROWTH_POLICY_H
39#define tsl_rh_assert(expr) assert(expr)
41#define tsl_rh_assert(expr) (static_cast<void>(0))
48#if (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || \
49 (defined(_MSC_VER) && defined(_CPPUNWIND))) && \
50 !defined(TSL_NO_EXCEPTIONS)
51#define TSL_RH_THROW_OR_TERMINATE(ex, msg) throw ex(msg)
53#define TSL_RH_NO_EXCEPTIONS
56#define TSL_RH_THROW_OR_TERMINATE(ex, msg) \
58 std::cerr << msg << std::endl; \
62#define TSL_RH_THROW_OR_TERMINATE(ex, msg) std::terminate()
66#if defined(__GNUC__) || defined(__clang__)
67#define TSL_RH_LIKELY(exp) (__builtin_expect(!!(exp), true))
69#define TSL_RH_LIKELY(exp) (exp)
72#define TSL_RH_UNUSED(x) static_cast<void>(x)
100 if (min_bucket_count_in_out > 0) {
102 m_mask = min_bucket_count_in_out - 1;
124 return (
m_mask + 1) * GrowthFactor;
133 return (std::numeric_limits<std::size_t>::max() / 2) + 1;
155 for (std::size_t i = 1; i <
sizeof(std::size_t) * CHAR_BIT; i *= 2) {
164 return value != 0 && (value & (value - 1)) == 0;
169 "GrowthFactor must be a power of two >= 2.");
188 if (min_bucket_count_in_out > 0) {
189 m_mod = min_bucket_count_in_out;
223 1.0 * GrowthFactor::num / GrowthFactor::den;
234#if SIZE_MAX >= ULLONG_MAX
235#define TSL_RH_NB_PRIMES 51
236#elif SIZE_MAX >= ULONG_MAX
237#define TSL_RH_NB_PRIMES 40
239#define TSL_RH_NB_PRIMES 23
242 static constexpr const std::array<std::size_t, TSL_RH_NB_PRIMES>
PRIMES = {{
266#if SIZE_MAX >= ULONG_MAX
285#if SIZE_MAX >= ULLONG_MAX
300 template <
unsigned int IPrime>
static constexpr std::size_t
mod(std::size_t hash)
302 return hash %
PRIMES[IPrime];
312#if SIZE_MAX >= ULONG_MAX
316#if SIZE_MAX >= ULLONG_MAX
363 if (min_bucket_count_in_out > 0) {
364 min_bucket_count_in_out = *it_prime;
367 min_bucket_count_in_out = 0;
393 "The type of m_iprime is not big enough.");
Definition robin_growth_policy.h:180
std::size_t m_mod
Definition robin_growth_policy.h:229
std::size_t next_bucket_count() const
Definition robin_growth_policy.h:198
std::size_t max_bucket_count() const
Definition robin_growth_policy.h:217
static const std::size_t MAX_BUCKET_COUNT
Definition robin_growth_policy.h:224
void clear() noexcept
Definition robin_growth_policy.h:219
std::size_t bucket_for_hash(std::size_t hash) const noexcept
Definition robin_growth_policy.h:196
mod_growth_policy(std::size_t &min_bucket_count_in_out)
Definition robin_growth_policy.h:182
static constexpr double REHASH_SIZE_MULTIPLICATION_FACTOR
Definition robin_growth_policy.h:222
Definition robin_growth_policy.h:84
std::size_t max_bucket_count() const
Definition robin_growth_policy.h:130
static std::size_t round_up_to_power_of_two(std::size_t value)
Definition robin_growth_policy.h:144
power_of_two_growth_policy(std::size_t &min_bucket_count_in_out)
Definition robin_growth_policy.h:94
std::size_t m_mask
Definition robin_growth_policy.h:171
std::size_t next_bucket_count() const
Definition robin_growth_policy.h:118
static constexpr bool is_power_of_two(std::size_t value)
Definition robin_growth_policy.h:162
std::size_t bucket_for_hash(std::size_t hash) const noexcept
Definition robin_growth_policy.h:113
void clear() noexcept
Definition robin_growth_policy.h:141
Definition robin_growth_policy.h:352
std::size_t bucket_for_hash(std::size_t hash) const noexcept
Definition robin_growth_policy.h:371
std::size_t next_bucket_count() const
Definition robin_growth_policy.h:376
unsigned int m_iprime
Definition robin_growth_policy.h:390
prime_growth_policy(std::size_t &min_bucket_count_in_out)
Definition robin_growth_policy.h:354
std::size_t max_bucket_count() const
Definition robin_growth_policy.h:385
void clear() noexcept
Definition robin_growth_policy.h:387
static constexpr std::size_t mod(std::size_t hash)
Definition robin_growth_policy.h:300
static constexpr const std::array< std::size_t(*)(std::size_t), TSL_RH_NB_PRIMES > MOD_PRIME
Definition robin_growth_policy.h:308
static constexpr const std::array< std::size_t, TSL_RH_NB_PRIMES > PRIMES
Definition robin_growth_policy.h:242
Definition robin_growth_policy.h:74
#define TSL_RH_NB_PRIMES
Definition robin_growth_policy.h:235
#define TSL_RH_THROW_OR_TERMINATE(ex, msg)
Definition robin_growth_policy.h:62