mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 09:24:57 +00:00
AK: Support popping an arbitrary element from a HashTable
This commit is contained in:
parent
e80f0b23e3
commit
a2024cfb69
1 changed files with 18 additions and 0 deletions
|
@ -442,6 +442,24 @@ public:
|
|||
return removed_count;
|
||||
}
|
||||
|
||||
T pop()
|
||||
{
|
||||
VERIFY(!is_empty());
|
||||
T element;
|
||||
if constexpr (IsOrdered) {
|
||||
element = *m_collection_data.tail->slot();
|
||||
} else {
|
||||
for (size_t i = 0; i < m_capacity; ++i) {
|
||||
if (is_used_bucket(m_buckets[i].state)) {
|
||||
element = *m_buckets[i].slot();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
remove(element);
|
||||
return element;
|
||||
}
|
||||
|
||||
private:
|
||||
void insert_during_rehash(T&& value)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue