mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 07:37:35 +00:00
AK: Add OOM safe interface to HashTable/Map
This adds a new HashSetResult only returned by try_set, to signal allocation failure during setting.
This commit is contained in:
parent
f36781a8bc
commit
1aa527f5b6
2 changed files with 68 additions and 31 deletions
|
@ -57,6 +57,9 @@ public:
|
|||
|
||||
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) }); }
|
||||
HashSetResult try_set(const K& key, const V& value) { return m_table.try_set({ key, value }); }
|
||||
HashSetResult try_set(const K& key, V&& value) { return m_table.try_set({ key, move(value) }); }
|
||||
|
||||
bool remove(const K& key)
|
||||
{
|
||||
auto it = find(key);
|
||||
|
@ -96,6 +99,7 @@ public:
|
|||
}
|
||||
|
||||
void ensure_capacity(size_t capacity) { m_table.ensure_capacity(capacity); }
|
||||
bool try_ensure_capacity(size_t capacity) { return m_table.try_ensure_capacity(capacity); }
|
||||
|
||||
Optional<typename Traits<V>::PeekType> get(const K& key) const requires(!IsPointer<typename Traits<V>::PeekType>)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue