mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 22:27:35 +00:00
AK: HashTable/HashMap return whether action was performed for set/remove
This allows performing an action based on whether something was actually added or removed without having to look it up prior to calling set() or remove().
This commit is contained in:
parent
df54229954
commit
dadd53e4f2
2 changed files with 25 additions and 12 deletions
11
AK/HashMap.h
11
AK/HashMap.h
|
@ -54,13 +54,16 @@ public:
|
|||
size_t capacity() const { return m_table.capacity(); }
|
||||
void clear() { m_table.clear(); }
|
||||
|
||||
void set(const K& key, const V& value) { m_table.set({ key, value }); }
|
||||
void set(const K& key, V&& value) { m_table.set({ key, move(value) }); }
|
||||
void remove(const K& key)
|
||||
HashSetResult set(const K& key, const V& value) { return m_table.set({ key, value }); }
|
||||
HashSetResult set(const K& key, V&& value) { return m_table.set({ key, move(value) }); }
|
||||
bool remove(const K& key)
|
||||
{
|
||||
auto it = find(key);
|
||||
if (it != end())
|
||||
if (it != end()) {
|
||||
m_table.remove(it);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
void remove_one_randomly() { m_table.remove(m_table.begin()); }
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue