mirror of
https://github.com/SerenityOS/serenity
synced 2024-07-21 18:15:58 +00:00
AK: Enable fast path for removal by hash-compatible key in HashMap/Table
This commit is contained in:
parent
b429f9c7aa
commit
c673b7220a
11
AK/HashMap.h
11
AK/HashMap.h
|
@ -63,6 +63,17 @@ public:
|
|||
return false;
|
||||
}
|
||||
|
||||
template<Concepts::HashCompatible<K> Key>
|
||||
requires(IsSame<KeyTraits, Traits<K>>) bool remove(Key const& key)
|
||||
{
|
||||
auto it = find(key);
|
||||
if (it != end()) {
|
||||
m_table.remove(it);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
using HashTableType = HashTable<Entry, EntryTraits, IsOrdered>;
|
||||
using IteratorType = typename HashTableType::Iterator;
|
||||
using ConstIteratorType = typename HashTableType::ConstIterator;
|
||||
|
|
|
@ -373,6 +373,17 @@ public:
|
|||
return false;
|
||||
}
|
||||
|
||||
template<Concepts::HashCompatible<T> K>
|
||||
requires(IsSame<TraitsForT, Traits<T>>) bool remove(K const& value)
|
||||
{
|
||||
auto it = find(value);
|
||||
if (it != end()) {
|
||||
remove(it);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void remove(Iterator iterator)
|
||||
{
|
||||
VERIFY(iterator.m_bucket);
|
||||
|
|
Loading…
Reference in a new issue