mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 13:17:35 +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
1 changed files with 11 additions and 2 deletions
|
@ -446,10 +446,19 @@ public:
|
||||||
insert(key, V(value));
|
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)
|
void insert(K key, V&& value)
|
||||||
{
|
{
|
||||||
auto* node = new Node(key, move(value));
|
auto success = try_insert(key, move(value));
|
||||||
BaseTree::insert(node);
|
VERIFY(success);
|
||||||
}
|
}
|
||||||
|
|
||||||
using Iterator = RedBlackTreeIterator<RedBlackTree, V>;
|
using Iterator = RedBlackTreeIterator<RedBlackTree, V>;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue