summaryrefslogtreecommitdiff
path: root/AK/HashTable.h
diff options
context:
space:
mode:
Diffstat (limited to 'AK/HashTable.h')
-rw-r--r--AK/HashTable.h7
1 files changed, 5 insertions, 2 deletions
diff --git a/AK/HashTable.h b/AK/HashTable.h
index 8d3bf7cd2a..cd53fb202b 100644
--- a/AK/HashTable.h
+++ b/AK/HashTable.h
@@ -74,6 +74,8 @@ private:
template<typename T, typename TraitsForT>
class HashTable {
+ static constexpr size_t load_factor_in_percent = 60;
+
struct Bucket {
bool used;
bool deleted;
@@ -348,8 +350,8 @@ private:
return *const_cast<Bucket*>(bucket_for_reading);
}
- if ((used_bucket_count() + 1) >= m_capacity)
- rehash((size() + 1) * 2);
+ if (should_grow())
+ rehash(capacity() * 2);
else if (usable_bucket_for_writing)
return *usable_bucket_for_writing;
@@ -365,6 +367,7 @@ private:
}
size_t used_bucket_count() const { return m_size + m_deleted_count; }
+ bool should_grow() const { return ((used_bucket_count() + 1) * 100) >= (m_capacity * load_factor_in_percent); }
Bucket* m_buckets { nullptr };
size_t m_size { 0 };