This commit is contained in:
Nikita Taranov 2022-06-25 01:25:34 +02:00
parent f6ef78c0f1
commit c476427422
4 changed files with 13 additions and 8 deletions

View File

@ -72,7 +72,11 @@ namespace detail
// Unlike HashTableGrower always grows to power of 2.
struct UniqCombinedHashTableGrower : public HashTableGrower<>
{
void increaseSize() { ++size_degree; }
void increaseSize()
{
++size_degree;
updateCachedValues();
}
};
template <typename Key, UInt8 K>

View File

@ -232,12 +232,13 @@ class HashTableGrower
{
/// The state of this structure is enough to get the buffer size of the hash table.
UInt8 size_degree = initial_size_degree;
size_t cached_mask = (1ULL << initial_size_degree) - 1;
size_t cached_max_fill = 1ULL << (initial_size_degree - 1);
protected:
void updateSizeDegree()
UInt8 size_degree = initial_size_degree;
void updateCachedValues()
{
cached_mask = (1ULL << size_degree) - 1;
cached_max_fill = 1ULL << (size_degree - 1);
@ -268,7 +269,7 @@ public:
void increaseSize()
{
size_degree += size_degree >= 23 ? 1 : 2;
updateMask();
updateCachedValues();
}
/// Set the buffer size by the number of elements in the hash table. Used when deserializing a hash table.
@ -279,13 +280,13 @@ public:
: ((initial_size_degree > static_cast<size_t>(log2(num_elems - 1)) + 2)
? initial_size_degree
: (static_cast<size_t>(log2(num_elems - 1)) + 2));
updateMask();
updateCachedValues();
}
void setBufSize(size_t buf_size_)
{
size_degree = static_cast<size_t>(log2(buf_size_ - 1) + 1);
updateMask();
updateCachedValues();
}
};

View File

@ -156,7 +156,7 @@ struct StringHashTableGrower : public HashTableGrower<initial_size_degree>
void increaseSize()
{
this->size_degree += 1;
HashTableGrower<initial_size_degree>::updateMask();
HashTableGrower<initial_size_degree>::updateCachedValues();
}
};

View File

@ -21,7 +21,7 @@ struct TwoLevelHashTableGrower : public HashTableGrower<initial_size_degree>
void increaseSize()
{
this->size_degree += this->size_degree >= 15 ? 1 : 2;
HashTableGrower<initial_size_degree>::updateMask();
HashTableGrower<initial_size_degree>::updateCachedValues();
}
};