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:
parent
41dae9b3c7
commit
2bddf157b1
Notes:
sideshowbarker
2024-07-17 19:03:23 +09:00
Author: https://github.com/davidot
Commit: 2bddf157b1
Pull-request: https://github.com/SerenityOS/serenity/pull/12412
Reviewed-by: https://github.com/IdanHo
Reviewed-by: https://github.com/alimpfard ✅
2 changed files with 49 additions and 4 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue