From 2c1c4ab116f1e666ffb6cbef41b3ce3b8867d9b5 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 24 Jun 2019 11:57:54 +0200 Subject: [PATCH] AK: Make it possible to move and copy HashMap and HashTable. Previously it was only possible to move them, but we should allow copying as well, since it's gonna be useful for many things. --- AK/HashMap.h | 13 ------------- AK/HashTable.h | 18 +++++++++++++++++- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/AK/HashMap.h b/AK/HashMap.h index bd58a5a8e6..1ecd5e554d 100644 --- a/AK/HashMap.h +++ b/AK/HashMap.h @@ -34,19 +34,6 @@ private: public: HashMap() {} - HashMap(HashMap&& other) - : m_table(move(other.m_table)) - { - } - - HashMap& operator=(HashMap&& other) - { - if (this != &other) { - m_table = move(other.m_table); - } - return *this; - } - bool is_empty() const { return m_table.is_empty(); } int size() const { return m_table.size(); } int capacity() const { return m_table.capacity(); } diff --git a/AK/HashTable.h b/AK/HashTable.h index 7720a38f86..78ef573b69 100644 --- a/AK/HashTable.h +++ b/AK/HashTable.h @@ -22,7 +22,23 @@ private: public: HashTable() {} - explicit HashTable(HashTable&& other) + HashTable(const HashTable& other) + { + ensure_capacity(other.size()); + for (auto& it : other) + set(it); + } + HashTable& operator=(const HashTable& other) + { + if (this != &other) { + clear(); + ensure_capacity(other.size()); + for (auto& it : other) + set(it); + } + return *this; + } + HashTable(HashTable&& other) : m_buckets(other.m_buckets) , m_size(other.m_size) , m_capacity(other.m_capacity)