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:
Idan Horowitz 2021-07-15 01:00:29 +03:00 committed by Andreas Kling
parent a9a54914bf
commit e94dfb7355
Notes: sideshowbarker 2024-07-18 09:00:48 +09:00

View File

@ -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>;