AK: Add RBTree::find_smallest_above_iterator(Key)

This commit is contained in:
Ali Mohammad Pur 2022-02-09 16:33:44 +03:30 committed by Linus Groh
parent 9ff22ac7e0
commit e7dea10381

View file

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