libluna: Fix initial allocation for HashTable

This commit is contained in:
apio 2023-08-27 20:48:50 +02:00
parent 6f3ed70363
commit a772d92e6f
Signed by: apio
GPG Key ID: B8A7D06E42258954

View File

@ -21,6 +21,7 @@ template <typename T> class HashTable
{
static constexpr usize GROW_RATE = 2;
static constexpr usize GROW_FACTOR = 2;
static constexpr usize INITIAL_CAPACITY = 32;
public:
/**
@ -43,7 +44,7 @@ template <typename T> class HashTable
*/
Result<bool> try_set(T&& value)
{
if (should_grow()) TRY(rehash(m_capacity * GROW_FACTOR));
if (should_grow()) TRY(rehash(m_capacity ? m_capacity * GROW_FACTOR : INITIAL_CAPACITY));
u64 index = hash(value, m_salt) % m_capacity;