mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 00:50:22 +00:00
AK: Add RBTree::find_smallest_above_iterator(Key)
This commit is contained in:
parent
9ff22ac7e0
commit
e7dea10381
Notes:
sideshowbarker
2024-07-17 19:05:46 +09:00
Author: https://github.com/alimpfard Commit: https://github.com/SerenityOS/serenity/commit/e7dea10381 Pull-request: https://github.com/SerenityOS/serenity/pull/12383 Issue: https://github.com/SerenityOS/serenity/issues/11004 Reviewed-by: https://github.com/ADKaster Reviewed-by: https://github.com/IdanHo Reviewed-by: https://github.com/davidot ✅ Reviewed-by: https://github.com/linusg
1 changed files with 22 additions and 0 deletions
|
@ -131,6 +131,20 @@ protected:
|
|||
return candidate;
|
||||
}
|
||||
|
||||
static Node* find_smallest_not_below(Node* node, K key)
|
||||
{
|
||||
while (node) {
|
||||
if (node->key >= key && (!node->left_child || node->left_child->key < key))
|
||||
return node;
|
||||
|
||||
if (node->key <= key)
|
||||
node = node->right_child;
|
||||
else
|
||||
node = node->left_child;
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
void insert(Node* node)
|
||||
{
|
||||
VERIFY(node);
|
||||
|
@ -493,6 +507,14 @@ public:
|
|||
return ConstIterator(node, static_cast<Node*>(BaseTree::predecessor(node)));
|
||||
}
|
||||
|
||||
ConstIterator find_smallest_not_below_iterator(K key) const
|
||||
{
|
||||
auto node = static_cast<Node*>(BaseTree::find_smallest_not_below(this->m_root, key));
|
||||
if (!node)
|
||||
return end();
|
||||
return ConstIterator(node, static_cast<Node*>(BaseTree::predecessor(node)));
|
||||
}
|
||||
|
||||
V unsafe_remove(K key)
|
||||
{
|
||||
auto* node = BaseTree::find(this->m_root, key);
|
||||
|
|
Loading…
Reference in a new issue