mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 02:47:35 +00:00
AK: Make Hash{Map,Table}::remove_all_matching() return removal success
These functions now return whether one or more entries were removed.
This commit is contained in:
parent
c7ac0c2c80
commit
5279a04c78
4 changed files with 24 additions and 12 deletions
10
AK/HashMap.h
10
AK/HashMap.h
|
@ -75,14 +75,18 @@ public:
|
|||
}
|
||||
|
||||
template<typename TUnaryPredicate>
|
||||
void remove_all_matching(TUnaryPredicate predicate)
|
||||
bool remove_all_matching(TUnaryPredicate predicate)
|
||||
{
|
||||
bool something_was_removed = false;
|
||||
for (auto it = begin(); it != end();) {
|
||||
if (predicate(it->key, it->value))
|
||||
if (predicate(it->key, it->value)) {
|
||||
it = remove(it);
|
||||
else
|
||||
something_was_removed = true;
|
||||
} else {
|
||||
++it;
|
||||
}
|
||||
}
|
||||
return something_was_removed;
|
||||
}
|
||||
|
||||
using HashTableType = HashTable<Entry, EntryTraits, IsOrdered>;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue