1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-09 09:34:57 +09:00

AK: Fix RedBlackTree::find_smallest_not_below_iterator

Before this was incorrectly assuming that if the current node `n` was at
least the key and the left child of `n` was below the key that `n` was
always correct.
However, the right child(ren) of the left child of `n` could still be
at least the key.

Also added some tests which produced the wrong results before this.
This commit is contained in:
davidot 2022-02-10 10:36:09 +01:00 committed by Linus Groh
parent 41dae9b3c7
commit 2bddf157b1
Notes: sideshowbarker 2024-07-17 19:03:23 +09:00
2 changed files with 49 additions and 4 deletions

View file

@ -133,16 +133,19 @@ protected:
static Node* find_smallest_not_below(Node* node, K key)
{
Node* candidate = nullptr;
while (node) {
if (node->key >= key && (!node->left_child || node->left_child->key < key))
if (node->key == key)
return node;
if (node->key <= key)
if (node->key <= key) {
node = node->right_child;
else
} else {
candidate = node;
node = node->left_child;
}
}
return node;
return candidate;
}
void insert(Node* node)