mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 09:14:58 +00:00
AK: Add HashTable::remove_all_matching(predicate)
This removes all matching entries from a table in a single pass.
This commit is contained in:
parent
365bd8a0c3
commit
54cf42fac1
2 changed files with 37 additions and 1 deletions
|
@ -384,7 +384,7 @@ public:
|
|||
return false;
|
||||
}
|
||||
|
||||
void remove(Iterator iterator)
|
||||
Iterator remove(Iterator iterator)
|
||||
{
|
||||
VERIFY(iterator.m_bucket);
|
||||
auto& bucket = *iterator.m_bucket;
|
||||
|
@ -394,6 +394,9 @@ public:
|
|||
if constexpr (!IsOrdered)
|
||||
VERIFY(!bucket.end);
|
||||
|
||||
auto next_iterator = iterator;
|
||||
++next_iterator;
|
||||
|
||||
bucket.slot()->~T();
|
||||
bucket.used = false;
|
||||
bucket.deleted = true;
|
||||
|
@ -411,6 +414,19 @@ public:
|
|||
else
|
||||
m_collection_data.tail = bucket.previous;
|
||||
}
|
||||
|
||||
return next_iterator;
|
||||
}
|
||||
|
||||
template<typename TUnaryPredicate>
|
||||
void remove_all_matching(TUnaryPredicate predicate)
|
||||
{
|
||||
for (auto it = begin(); it != end();) {
|
||||
if (predicate(*it))
|
||||
it = remove(it);
|
||||
else
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue