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.");