From a772d92e6f85ea19ceec03b15da1da67cc35e6da Mon Sep 17 00:00:00 2001 From: apio Date: Sun, 27 Aug 2023 20:48:50 +0200 Subject: [PATCH] libluna: Fix initial allocation for HashTable --- libluna/include/luna/HashTable.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libluna/include/luna/HashTable.h b/libluna/include/luna/HashTable.h index 18e255bb..a29e86d7 100644 --- a/libluna/include/luna/HashTable.h +++ b/libluna/include/luna/HashTable.h @@ -21,6 +21,7 @@ template 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 class HashTable */ Result 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;