mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
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.
This commit is contained in:
parent
009b9bfd10
commit
2c1c4ab116
Notes:
sideshowbarker
2024-07-19 13:29:42 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/2c1c4ab116f
2 changed files with 17 additions and 14 deletions
13
AK/HashMap.h
13
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(); }
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue