Introduce max_size_degree for HashTableGrower{,WithPrecalculation}

Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>
This commit is contained in:
Azat Khuzhin 2023-05-15 19:54:20 +02:00
parent 42eac6bfbc
commit 634f168a74

View File

@ -230,6 +230,8 @@ struct HashTableGrower
/// If collision resolution chains are contiguous, we can implement erase operation by moving the elements. /// If collision resolution chains are contiguous, we can implement erase operation by moving the elements.
static constexpr auto performs_linear_probing_with_single_step = true; static constexpr auto performs_linear_probing_with_single_step = true;
static constexpr size_t max_size_degree = 23;
/// The size of the hash table in the cells. /// The size of the hash table in the cells.
size_t bufSize() const { return 1ULL << size_degree; } size_t bufSize() const { return 1ULL << size_degree; }
@ -248,7 +250,7 @@ struct HashTableGrower
/// Increase the size of the hash table. /// Increase the size of the hash table.
void increaseSize() void increaseSize()
{ {
size_degree += size_degree >= 23 ? 1 : 2; size_degree += size_degree >= max_size_degree ? 1 : 2;
} }
/// Set the buffer size by the number of elements in the hash table. Used when deserializing a hash table. /// Set the buffer size by the number of elements in the hash table. Used when deserializing a hash table.
@ -280,6 +282,7 @@ class alignas(64) HashTableGrowerWithPrecalculation
UInt8 size_degree = initial_size_degree; UInt8 size_degree = initial_size_degree;
size_t precalculated_mask = (1ULL << initial_size_degree) - 1; size_t precalculated_mask = (1ULL << initial_size_degree) - 1;
size_t precalculated_max_fill = 1ULL << (initial_size_degree - 1); size_t precalculated_max_fill = 1ULL << (initial_size_degree - 1);
static constexpr size_t max_size_degree = 23;
public: public:
UInt8 sizeDegree() const { return size_degree; } UInt8 sizeDegree() const { return size_degree; }
@ -309,7 +312,7 @@ public:
bool overflow(size_t elems) const { return elems > precalculated_max_fill; } bool overflow(size_t elems) const { return elems > precalculated_max_fill; }
/// Increase the size of the hash table. /// Increase the size of the hash table.
void increaseSize() { increaseSizeDegree(size_degree >= 23 ? 1 : 2); } void increaseSize() { increaseSizeDegree(size_degree >= max_size_degree ? 1 : 2); }
/// Set the buffer size by the number of elements in the hash table. Used when deserializing a hash table. /// Set the buffer size by the number of elements in the hash table. Used when deserializing a hash table.
void set(size_t num_elems) void set(size_t num_elems)