mirror of
https://github.com/SerenityOS/serenity
synced 2024-07-21 18:15:58 +00:00
AK: Expose RedBlackTree allocation failures via try_insert
This should help with using the RedBlackTree in a more OOM-safe way in the kernel.
This commit is contained in:
parent
a9a54914bf
commit
e94dfb7355
|
@ -446,10 +446,19 @@ public:
|
|||
insert(key, V(value));
|
||||
}
|
||||
|
||||
[[nodiscard]] bool try_insert(K key, V&& value)
|
||||
{
|
||||
auto* node = new (nothrow) Node(key, move(value));
|
||||
if (!node)
|
||||
return false;
|
||||
BaseTree::insert(node);
|
||||
return true;
|
||||
}
|
||||
|
||||
void insert(K key, V&& value)
|
||||
{
|
||||
auto* node = new Node(key, move(value));
|
||||
BaseTree::insert(node);
|
||||
auto success = try_insert(key, move(value));
|
||||
VERIFY(success);
|
||||
}
|
||||
|
||||
using Iterator = RedBlackTreeIterator<RedBlackTree, V>;
|
||||
|
|
Loading…
Reference in a new issue