24 #ifndef TSL_HOPSCOTCH_GROWTH_POLICY_H 25 #define TSL_HOPSCOTCH_GROWTH_POLICY_H 61 throw std::length_error(
"The hash table exceeds its maxmimum size.");
64 if (min_bucket_count_in_out > 0) {
66 m_mask = min_bucket_count_in_out - 1;
85 throw std::length_error(
"The hash table exceeds its maxmimum size.");
88 return (
m_mask + 1) * GrowthFactor;
97 return (std::numeric_limits<std::size_t>::max() / 2) + 1;
118 for (std::size_t i = 1; i <
sizeof(std::size_t) * CHAR_BIT; i *= 2) {
127 return value != 0 && (value & (value - 1)) == 0;
132 "GrowthFactor must be a power of two >= 2.");
147 throw std::length_error(
"The hash table exceeds its maxmimum size.");
150 if (min_bucket_count_in_out > 0) {
151 m_mod = min_bucket_count_in_out;
163 throw std::length_error(
"The hash table exceeds its maxmimum size.");
169 throw std::length_error(
"The hash table exceeds its maxmimum size.");
186 1.0 * GrowthFactor::num / GrowthFactor::den;
197 static constexpr
const std::array<std::size_t, 40>
PRIMES = {
198 {1ul, 5ul, 17ul, 29ul, 37ul, 53ul,
199 67ul, 79ul, 97ul, 131ul, 193ul, 257ul,
200 389ul, 521ul, 769ul, 1031ul, 1543ul, 2053ul,
201 3079ul, 6151ul, 12289ul, 24593ul, 49157ul, 98317ul,
202 196613ul, 393241ul, 786433ul, 1572869ul, 3145739ul, 6291469ul,
203 12582917ul, 25165843ul, 50331653ul, 100663319ul, 201326611ul, 402653189ul,
204 805306457ul, 1610612741ul, 3221225473ul, 4294967291ul}};
206 template <
unsigned int IPrime>
static constexpr std::size_t
mod(std::size_t hash)
208 return hash %
PRIMES[IPrime];
214 static constexpr
const std::array<std::size_t (*)(std::size_t), 40>
MOD_PRIME = {
215 {&mod<0>, &mod<1>, &mod<2>, &mod<3>, &mod<4>, &mod<5>, &mod<6>, &mod<7>,
216 &mod<8>, &mod<9>, &mod<10>, &mod<11>, &mod<12>, &mod<13>, &mod<14>, &mod<15>,
217 &mod<16>, &mod<17>, &mod<18>, &mod<19>, &mod<20>, &mod<21>, &mod<22>, &mod<23>,
218 &mod<24>, &mod<25>, &mod<26>, &mod<27>, &mod<28>, &mod<29>, &mod<30>, &mod<31>,
219 &mod<32>, &mod<33>, &mod<34>, &mod<35>, &mod<36>, &mod<37>, &mod<38>, &mod<39>}};
258 throw std::length_error(
"The hash table exceeds its maxmimum size.");
262 if (min_bucket_count_in_out > 0) {
263 min_bucket_count_in_out = *it_prime;
266 min_bucket_count_in_out = 0;
278 throw std::length_error(
"The hash table exceeds its maxmimum size.");
292 "The type of m_iprime is not big enough.");
prime_growth_policy(std::size_t &min_bucket_count_in_out)
Definition: hopscotch_growth_policy.h:253
std::size_t max_bucket_count() const
Definition: hopscotch_growth_policy.h:284
std::size_t m_mask
Definition: hopscotch_growth_policy.h:132
static constexpr bool is_power_of_two(std::size_t value)
Definition: hopscotch_growth_policy.h:125
Definition: hopscotch_growth_policy.h:37
std::size_t m_mod
Definition: hopscotch_growth_policy.h:190
static const std::size_t MAX_BUCKET_COUNT
Definition: hopscotch_growth_policy.h:187
unsigned int m_iprime
Definition: hopscotch_growth_policy.h:289
std::size_t bucket_for_hash(std::size_t hash) const noexcept
Definition: hopscotch_growth_policy.h:270
static std::size_t round_up_to_power_of_two(std::size_t value)
Definition: hopscotch_growth_policy.h:107
Definition: hopscotch_growth_policy.h:141
void clear() noexcept
Definition: hopscotch_growth_policy.h:104
std::size_t bucket_for_hash(std::size_t hash) const noexcept
Definition: hopscotch_growth_policy.h:77
void clear() noexcept
Definition: hopscotch_growth_policy.h:286
static constexpr std::size_t mod(std::size_t hash)
Definition: hopscotch_growth_policy.h:206
void clear() noexcept
Definition: hopscotch_growth_policy.h:182
static constexpr double REHASH_SIZE_MULTIPLICATION_FACTOR
Definition: hopscotch_growth_policy.h:185
std::size_t next_bucket_count() const
Definition: hopscotch_growth_policy.h:275
Definition: hopscotch_growth_policy.h:47
static constexpr const std::array< std::size_t, 40 > PRIMES
Definition: hopscotch_growth_policy.h:197
Definition: hopscotch_growth_policy.h:250
std::size_t max_bucket_count() const
Definition: hopscotch_growth_policy.h:94
static constexpr const std::array< std::size_t(*)(std::size_t), 40 > MOD_PRIME
Definition: hopscotch_growth_policy.h:214
std::size_t max_bucket_count() const
Definition: hopscotch_growth_policy.h:180
mod_growth_policy(std::size_t &min_bucket_count_in_out)
Definition: hopscotch_growth_policy.h:144
std::size_t next_bucket_count() const
Definition: hopscotch_growth_policy.h:160
std::size_t next_bucket_count() const
Definition: hopscotch_growth_policy.h:82
power_of_two_growth_policy(std::size_t &min_bucket_count_in_out)
Definition: hopscotch_growth_policy.h:58
std::size_t bucket_for_hash(std::size_t hash) const noexcept
Definition: hopscotch_growth_policy.h:158