mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 17:47:44 +00:00
AK: Add HashMap::remove_all_matching(predicate)
This removes all matching entries from a hash map in a single pass.
This commit is contained in:
parent
e08d325124
commit
376e5ef912
2 changed files with 37 additions and 2 deletions
15
AK/HashMap.h
15
AK/HashMap.h
|
@ -74,6 +74,17 @@ public:
|
|||
return false;
|
||||
}
|
||||
|
||||
template<typename TUnaryPredicate>
|
||||
void remove_all_matching(TUnaryPredicate predicate)
|
||||
{
|
||||
for (auto it = begin(); it != end();) {
|
||||
if (predicate(it->key, it->value))
|
||||
it = remove(it);
|
||||
else
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
||||
using HashTableType = HashTable<Entry, EntryTraits, IsOrdered>;
|
||||
using IteratorType = typename HashTableType::Iterator;
|
||||
using ConstIteratorType = typename HashTableType::ConstIterator;
|
||||
|
@ -180,9 +191,9 @@ public:
|
|||
return find(value) != end();
|
||||
}
|
||||
|
||||
void remove(IteratorType it)
|
||||
IteratorType remove(IteratorType it)
|
||||
{
|
||||
m_table.remove(it);
|
||||
return m_table.remove(it);
|
||||
}
|
||||
|
||||
V& ensure(const K& key)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue