summaryrefslogtreecommitdiff
path: root/AK
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-05-27 13:07:20 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-05-27 13:07:20 +0200
commit12120167a9acc34a6cacf4153dc67b0fceba78a0 (patch)
tree08b818db1e4ac437a3cd4781597b9a758cb2fe01 /AK
parent4fb2e5d8af6200cb1c5de8fb104a9b2b4eb2252a (diff)
downloadserenity-12120167a9acc34a6cacf4153dc67b0fceba78a0.zip
AK: Add ensure_capacity() for HashMap and HashTable.
These functions make sure that the underlying table can accomodate at least 'capacity' entries before needing a rehash.
Diffstat (limited to 'AK')
-rw-r--r--AK/HashMap.h2
-rw-r--r--AK/HashTable.h6
2 files changed, 8 insertions, 0 deletions
diff --git a/AK/HashMap.h b/AK/HashMap.h
index a2f54cf216..828a9017e1 100644
--- a/AK/HashMap.h
+++ b/AK/HashMap.h
@@ -69,6 +69,8 @@ public:
ConstIteratorType end() const { return m_table.end(); }
ConstIteratorType find(const K&) const;
+ void ensure_capacity(int capacity) { m_table.ensure_capacity(capacity); }
+
void dump() const { m_table.dump(); }
V get(const K& key) const
diff --git a/AK/HashTable.h b/AK/HashTable.h
index 7a02060141..8a4b5f847d 100644
--- a/AK/HashTable.h
+++ b/AK/HashTable.h
@@ -49,6 +49,12 @@ public:
int size() const { return m_size; }
int capacity() const { return m_capacity; }
+ void ensure_capacity(int capacity)
+ {
+ ASSERT(capacity >= size());
+ rehash(capacity);
+ }
+
void set(const T&);
void set(T&&);
bool contains(const T&) const;