mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 05:47:34 +00:00
AK: Simplify HashTable::remove_all_matching()
Just walk the table from start to finish, deleting buckets as we go. This removes the need for remove() to return an iterator, which is preventing me from implementing hash table auto-shrinking.
This commit is contained in:
parent
6d1a9672a4
commit
623bdd8b6a
2 changed files with 35 additions and 33 deletions
13
AK/HashMap.h
13
AK/HashMap.h
|
@ -79,16 +79,9 @@ public:
|
|||
template<typename TUnaryPredicate>
|
||||
bool remove_all_matching(TUnaryPredicate predicate)
|
||||
{
|
||||
bool something_was_removed = false;
|
||||
for (auto it = begin(); it != end();) {
|
||||
if (predicate(it->key, it->value)) {
|
||||
it = remove(it);
|
||||
something_was_removed = true;
|
||||
} else {
|
||||
++it;
|
||||
}
|
||||
}
|
||||
return something_was_removed;
|
||||
return m_table.template remove_all_matching([&](auto& entry) {
|
||||
return predicate(entry.key, entry.value);
|
||||
});
|
||||
}
|
||||
|
||||
using HashTableType = HashTable<Entry, EntryTraits, IsOrdered>;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue