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
55#define TSL_RH_THROW_OR_TERMINATE(ex, msg) std::terminate()
58#define TSL_RH_THROW_OR_TERMINATE(ex, msg) \
60 std::cerr << msg << std::endl; \
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)
101 if (min_bucket_count_in_out > 0) {
103 m_mask = min_bucket_count_in_out - 1;
125 return (
m_mask + 1) * GrowthFactor;
134 return (std::numeric_limits<std::size_t>::max() / 2) + 1;
156 for (std::size_t i = 1; i <
sizeof(std::size_t) * CHAR_BIT; i *= 2) {
165 return value != 0 && (value & (value - 1)) == 0;
170 "GrowthFactor must be a power of two >= 2.");
189 if (min_bucket_count_in_out > 0) {
190 m_mod = min_bucket_count_in_out;
225 1.0 * GrowthFactor::num / GrowthFactor::den;
236#if SIZE_MAX >= ULLONG_MAX
237#define TSL_RH_NB_PRIMES 51
238#elif SIZE_MAX >= ULONG_MAX
239#define TSL_RH_NB_PRIMES 40
241#define TSL_RH_NB_PRIMES 23
244 static constexpr const std::array<std::size_t, TSL_RH_NB_PRIMES>
PRIMES = {{
268#if SIZE_MAX >= ULONG_MAX
287#if SIZE_MAX >= ULLONG_MAX
302 template <
unsigned int IPrime>
static constexpr std::size_t
mod(std::size_t hash)
304 return hash %
PRIMES[IPrime];
315#if SIZE_MAX >= ULONG_MAX
320#if SIZE_MAX >= ULLONG_MAX
367 if (min_bucket_count_in_out > 0) {
368 min_bucket_count_in_out = *it_prime;
371 min_bucket_count_in_out = 0;
397 "The type of m_iprime is not big enough.");
#define max(x, y)
Definition apr_aprepro.cc:898
Definition robin_growth_policy.h:181
std::size_t m_mod
Definition robin_growth_policy.h:231
std::size_t next_bucket_count() const
Definition robin_growth_policy.h:199
std::size_t max_bucket_count() const
Definition robin_growth_policy.h:219
static const std::size_t MAX_BUCKET_COUNT
Definition robin_growth_policy.h:226
void clear() noexcept
Definition robin_growth_policy.h:221
std::size_t bucket_for_hash(std::size_t hash) const noexcept
Definition robin_growth_policy.h:197
mod_growth_policy(std::size_t &min_bucket_count_in_out)
Definition robin_growth_policy.h:183
static constexpr double REHASH_SIZE_MULTIPLICATION_FACTOR
Definition robin_growth_policy.h:224
Definition robin_growth_policy.h:85
std::size_t max_bucket_count() const
Definition robin_growth_policy.h:131
static std::size_t round_up_to_power_of_two(std::size_t value)
Definition robin_growth_policy.h:145
power_of_two_growth_policy(std::size_t &min_bucket_count_in_out)
Definition robin_growth_policy.h:95
std::size_t m_mask
Definition robin_growth_policy.h:172
std::size_t next_bucket_count() const
Definition robin_growth_policy.h:119
static constexpr bool is_power_of_two(std::size_t value)
Definition robin_growth_policy.h:163
std::size_t bucket_for_hash(std::size_t hash) const noexcept
Definition robin_growth_policy.h:114
void clear() noexcept
Definition robin_growth_policy.h:142
Definition robin_growth_policy.h:356
std::size_t bucket_for_hash(std::size_t hash) const noexcept
Definition robin_growth_policy.h:375
std::size_t next_bucket_count() const
Definition robin_growth_policy.h:380
unsigned int m_iprime
Definition robin_growth_policy.h:394
prime_growth_policy(std::size_t &min_bucket_count_in_out)
Definition robin_growth_policy.h:358
std::size_t max_bucket_count() const
Definition robin_growth_policy.h:389
void clear() noexcept
Definition robin_growth_policy.h:391
static constexpr std::size_t mod(std::size_t hash)
Definition robin_growth_policy.h:302
static constexpr const std::array< std::size_t(*)(std::size_t), TSL_RH_NB_PRIMES > MOD_PRIME
Definition robin_growth_policy.h:310
static constexpr const std::array< std::size_t, TSL_RH_NB_PRIMES > PRIMES
Definition robin_growth_policy.h:244
Definition robin_growth_policy.h:74
#define TSL_RH_NB_PRIMES
Definition robin_growth_policy.h:237
#define TSL_RH_THROW_OR_TERMINATE(ex, msg)
Definition robin_growth_policy.h:58