mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-11 12:06:07 +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
Notes:
sideshowbarker
2024-07-18 04:20:38 +09:00
Author: https://github.com/Hendiadyoin1
Commit: 1aa527f5b6
Pull-request: https://github.com/SerenityOS/serenity/pull/9405
Reviewed-by: https://github.com/Dexesttp
Reviewed-by: https://github.com/sin-ack ✅
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