carl  24.04
Computer ARithmetic Library
PoolHelper.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <algorithm>
4 #include <cmath>
5 #include <cstddef>
6 #include <utility>
7 
8 namespace carl {
9 namespace pool {
10 
11 /**
12  * Mimics stdlibs default rehash policy for hashtables.
13  * See https://gcc.gnu.org/onlinedocs/libstdc++/libstdc++-html-USERS-4.1/hashtable-source.html
14  */
15 class RehashPolicy {
16  static const int numPrimes = sizeof(unsigned long) != 8 ? 256 : 256 + 48;
17  static const unsigned long primes[256 + 48 + 1];
18 
19  float mMaxLoadFactor; // stdlib uses 1
20  float mGrowthFactor; // stdlib uses 2
21  mutable std::size_t mNextResize;
22 
23 public:
24  RehashPolicy(float maxLoadFactor = 0.95f, float growthFactor = 2.f)
25  : mMaxLoadFactor(maxLoadFactor), mGrowthFactor(growthFactor), mNextResize(0) {}
26 
27  std::size_t numBucketsFor(std::size_t numElements) const;
28  std::pair<bool, std::size_t> needRehash(std::size_t numBuckets, std::size_t numElements) const;
29 };
30 
31 } // namespace pool
32 } // namespace carl
carl is the main namespace for the library.
Mimics stdlibs default rehash policy for hashtables.
Definition: PoolHelper.h:15
std::size_t mNextResize
Definition: PoolHelper.h:21
std::pair< bool, std::size_t > needRehash(std::size_t numBuckets, std::size_t numElements) const
Definition: PoolHelper.cpp:14
static const unsigned long primes[256+48+1]
Definition: PoolHelper.h:17
RehashPolicy(float maxLoadFactor=0.95f, float growthFactor=2.f)
Definition: PoolHelper.h:24
static const int numPrimes
Definition: PoolHelper.h:16
std::size_t numBucketsFor(std::size_t numElements) const
Definition: PoolHelper.cpp:7