AK: Add a method to remove an iterated node from a RedBlackTree
This will also advance the passed iterator so that it remains valid.
This commit is contained in:
parent
c4514c27ab
commit
ecae6f42cd
1 changed files with 19 additions and 0 deletions
|
|
@ -559,6 +559,25 @@ public:
|
|||
return temp;
|
||||
}
|
||||
|
||||
V remove_and_advance(Iterator& iterator)
|
||||
{
|
||||
VERIFY(!iterator.is_end());
|
||||
|
||||
auto* node = iterator.m_node;
|
||||
auto* successor = static_cast<Node*>(BaseTree::successor(node));
|
||||
iterator.m_node = successor;
|
||||
|
||||
BaseTree::remove(node);
|
||||
|
||||
V temp = move(node->value);
|
||||
|
||||
node->right_child = nullptr;
|
||||
node->left_child = nullptr;
|
||||
delete node;
|
||||
|
||||
return temp;
|
||||
}
|
||||
|
||||
bool remove(K key)
|
||||
{
|
||||
auto* node = BaseTree::find(this->m_root, key);
|
||||
|
|
|
|||
Loading…
Reference in a new issue