mirror of
https://github.com/SerenityOS/serenity
synced 2024-09-06 08:56:40 +00:00
AK: Add RBTree::find_smallest_above_iterator(Key)
This commit is contained in:
parent
9ff22ac7e0
commit
e7dea10381
|
@ -131,6 +131,20 @@ protected:
|
||||||
return candidate;
|
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)
|
void insert(Node* node)
|
||||||
{
|
{
|
||||||
VERIFY(node);
|
VERIFY(node);
|
||||||
|
@ -493,6 +507,14 @@ public:
|
||||||
return ConstIterator(node, static_cast<Node*>(BaseTree::predecessor(node)));
|
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)
|
V unsafe_remove(K key)
|
||||||
{
|
{
|
||||||
auto* node = BaseTree::find(this->m_root, key);
|
auto* node = BaseTree::find(this->m_root, key);
|
||||||
|
|
Loading…
Reference in a new issue