24#ifndef TSL_HOPSCOTCH_GROWTH_POLICY_H
25#define TSL_HOPSCOTCH_GROWTH_POLICY_H
45#define tsl_hh_assert(expr) assert(expr)
47#define tsl_hh_assert(expr) (static_cast<void>(0))
54#if (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || \
55 (defined(_MSC_VER) && defined(_CPPUNWIND))) && \
56 !defined(TSL_NO_EXCEPTIONS)
57#define TSL_HH_THROW_OR_TERMINATE(ex, msg) throw ex(msg)
59#define TSL_HH_NO_EXCEPTIONS
61#define TSL_HH_THROW_OR_TERMINATE(ex, msg) std::terminate()
64#define TSL_HH_THROW_OR_TERMINATE(ex, msg) \
66 std::cerr << msg << std::endl; \
98 if (min_bucket_count_in_out > 0) {
100 m_mask = min_bucket_count_in_out - 1;
122 return (
m_mask + 1) * GrowthFactor;
131 return (std::numeric_limits<std::size_t>::max() / 2) + 1;
153 for (std::size_t i = 1; i <
sizeof(std::size_t) * CHAR_BIT; i *= 2) {
162 return value != 0 && (value & (value - 1)) == 0;
167 "GrowthFactor must be a power of two >= 2.");
186 if (min_bucket_count_in_out > 0) {
187 m_mod = min_bucket_count_in_out;
221 1.0 * GrowthFactor::num / GrowthFactor::den;
232#if SIZE_MAX >= ULLONG_MAX
233#define TSL_HH_NB_PRIMES 51
234#elif SIZE_MAX >= ULONG_MAX
235#define TSL_HH_NB_PRIMES 40
237#define TSL_HH_NB_PRIMES 23
240 static constexpr const std::array<std::size_t, TSL_HH_NB_PRIMES>
PRIMES = {{
264#if SIZE_MAX >= ULONG_MAX
283#if SIZE_MAX >= ULLONG_MAX
298 template <
unsigned int IPrime>
static constexpr std::size_t
mod(std::size_t hash)
300 return hash %
PRIMES[IPrime];
310#if SIZE_MAX >= ULONG_MAX
314#if SIZE_MAX >= ULLONG_MAX
361 if (min_bucket_count_in_out > 0) {
362 min_bucket_count_in_out = *it_prime;
365 min_bucket_count_in_out = 0;
391 "The type of m_iprime is not big enough.");
Definition hopscotch_growth_policy.h:178
std::size_t bucket_for_hash(std::size_t hash) const noexcept
Definition hopscotch_growth_policy.h:194
std::size_t next_bucket_count() const
Definition hopscotch_growth_policy.h:196
std::size_t m_mod
Definition hopscotch_growth_policy.h:227
static const std::size_t MAX_BUCKET_COUNT
Definition hopscotch_growth_policy.h:222
std::size_t max_bucket_count() const
Definition hopscotch_growth_policy.h:215
void clear() noexcept
Definition hopscotch_growth_policy.h:217
static constexpr double REHASH_SIZE_MULTIPLICATION_FACTOR
Definition hopscotch_growth_policy.h:220
mod_growth_policy(std::size_t &min_bucket_count_in_out)
Definition hopscotch_growth_policy.h:180
Definition hopscotch_growth_policy.h:82
std::size_t bucket_for_hash(std::size_t hash) const noexcept
Definition hopscotch_growth_policy.h:111
void clear() noexcept
Definition hopscotch_growth_policy.h:139
std::size_t m_mask
Definition hopscotch_growth_policy.h:169
std::size_t max_bucket_count() const
Definition hopscotch_growth_policy.h:128
static std::size_t round_up_to_power_of_two(std::size_t value)
Definition hopscotch_growth_policy.h:142
power_of_two_growth_policy(std::size_t &min_bucket_count_in_out)
Definition hopscotch_growth_policy.h:92
static constexpr bool is_power_of_two(std::size_t value)
Definition hopscotch_growth_policy.h:160
std::size_t next_bucket_count() const
Definition hopscotch_growth_policy.h:116
Definition hopscotch_growth_policy.h:350
std::size_t next_bucket_count() const
Definition hopscotch_growth_policy.h:374
std::size_t max_bucket_count() const
Definition hopscotch_growth_policy.h:383
prime_growth_policy(std::size_t &min_bucket_count_in_out)
Definition hopscotch_growth_policy.h:352
void clear() noexcept
Definition hopscotch_growth_policy.h:385
unsigned int m_iprime
Definition hopscotch_growth_policy.h:388
std::size_t bucket_for_hash(std::size_t hash) const noexcept
Definition hopscotch_growth_policy.h:369
#define TSL_HH_NB_PRIMES
Definition hopscotch_growth_policy.h:233
#define TSL_HH_THROW_OR_TERMINATE(ex, msg)
Definition hopscotch_growth_policy.h:64
static constexpr const std::array< std::size_t(*)(std::size_t), TSL_HH_NB_PRIMES > MOD_PRIME
Definition hopscotch_growth_policy.h:306
static constexpr std::size_t mod(std::size_t hash)
Definition hopscotch_growth_policy.h:298
static constexpr const std::array< std::size_t, TSL_HH_NB_PRIMES > PRIMES
Definition hopscotch_growth_policy.h:240
Definition hopscotch_growth_policy.h:72