mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 05:07:45 +00:00
AK: Implement HashTable assignment in terms of swap
This commit is contained in:
parent
7f3f63dd92
commit
d30c559774
1 changed files with 5 additions and 15 deletions
|
@ -100,16 +100,12 @@ public:
|
||||||
|
|
||||||
HashTable& operator=(const HashTable& other)
|
HashTable& operator=(const HashTable& other)
|
||||||
{
|
{
|
||||||
if (this != &other) {
|
HashTable temporary(other);
|
||||||
clear();
|
swap(*this, temporary);
|
||||||
rehash(other.capacity());
|
|
||||||
for (auto& it : other)
|
|
||||||
set(it);
|
|
||||||
}
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
HashTable(HashTable&& other)
|
HashTable(HashTable&& other) noexcept
|
||||||
: m_buckets(other.m_buckets)
|
: m_buckets(other.m_buckets)
|
||||||
, m_size(other.m_size)
|
, m_size(other.m_size)
|
||||||
, m_capacity(other.m_capacity)
|
, m_capacity(other.m_capacity)
|
||||||
|
@ -121,15 +117,9 @@ public:
|
||||||
other.m_buckets = nullptr;
|
other.m_buckets = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
HashTable& operator=(HashTable&& other)
|
HashTable& operator=(HashTable&& other) noexcept
|
||||||
{
|
{
|
||||||
if (this != &other) {
|
swap(*this, other);
|
||||||
clear();
|
|
||||||
m_buckets = exchange(other.m_buckets, nullptr);
|
|
||||||
m_size = exchange(other.m_size, 0);
|
|
||||||
m_capacity = exchange(other.m_capacity, 0);
|
|
||||||
m_deleted_count = exchange(other.m_deleted_count, 0);
|
|
||||||
}
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue