From ebe108efa659f45f1fbfb889006b36307979b2f0 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 27 Jun 2019 14:19:50 +0200 Subject: [PATCH] AK: Simplify HashMap a bit. --- AK/HashMap.h | 47 +++++++---------------------------------------- 1 file changed, 7 insertions(+), 40 deletions(-) diff --git a/AK/HashMap.h b/AK/HashMap.h index 1ecd5e554d..ea85b805a4 100644 --- a/AK/HashMap.h +++ b/AK/HashMap.h @@ -14,7 +14,7 @@ private: K key; V value; - bool operator==(const Entry& other) + bool operator==(const Entry& other) const { return key == other.key; } @@ -39,9 +39,9 @@ public: int capacity() const { return m_table.capacity(); } void clear() { m_table.clear(); } - void set(const K&, const V&); - void set(const K&, V&&); - void remove(const K&); + void set(const K& key, const V& value) { m_table.set({ key, value }); } + void set(const K& key, V&& value) { m_table.set({ key, move(value) }); } + void remove(const K& key) { m_table.remove({ key, V() }); } void remove_one_randomly() { m_table.remove(m_table.begin()); } typedef HashTable HashTableType; @@ -50,11 +50,11 @@ public: IteratorType begin() { return m_table.begin(); } IteratorType end() { return m_table.end(); } - IteratorType find(const K&); + IteratorType find(const K& key) { return m_table.find({ key, V() }); } ConstIteratorType begin() const { return m_table.begin(); } ConstIteratorType end() const { return m_table.end(); } - ConstIteratorType find(const K&) const; + ConstIteratorType find(const K& key) const { return m_table.find({ key, V() }); } void ensure_capacity(int capacity) { m_table.ensure_capacity(capacity); } @@ -96,42 +96,9 @@ public: } private: - HashTable m_table; + HashTableType m_table; }; -template -void HashMap::set(const K& key, V&& value) -{ - m_table.set(Entry { key, move(value) }); -} - -template -void HashMap::set(const K& key, const V& value) -{ - m_table.set(Entry { key, value }); -} - -template -void HashMap::remove(const K& key) -{ - Entry dummy { key, V() }; - m_table.remove(dummy); -} - -template -auto HashMap::find(const K& key) -> IteratorType -{ - Entry dummy { key, V() }; - return m_table.find(dummy); -} - -template -auto HashMap::find(const K& key) const -> ConstIteratorType -{ - Entry dummy { key, V() }; - return m_table.find(dummy); -} - } using AK::HashMap;