diff --git a/AK/HashMap.h b/AK/HashMap.h index 78a307e3ee..33251fde72 100644 --- a/AK/HashMap.h +++ b/AK/HashMap.h @@ -63,6 +63,17 @@ public: return false; } + template Key> + requires(IsSame>) bool remove(Key const& key) + { + auto it = find(key); + if (it != end()) { + m_table.remove(it); + return true; + } + return false; + } + using HashTableType = HashTable; using IteratorType = typename HashTableType::Iterator; using ConstIteratorType = typename HashTableType::ConstIterator; diff --git a/AK/HashTable.h b/AK/HashTable.h index 5be70d5735..cacd4bda42 100644 --- a/AK/HashTable.h +++ b/AK/HashTable.h @@ -373,6 +373,17 @@ public: return false; } + template K> + requires(IsSame>) 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);