mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 00:50:22 +00:00
AK: Clear minimum when removing last node of RedBlackTree
This commit is contained in:
parent
2bddf157b1
commit
fdbfe85a87
Notes:
sideshowbarker
2024-07-17 19:03:20 +09:00
Author: https://github.com/davidot Commit: https://github.com/SerenityOS/serenity/commit/fdbfe85a87 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 15 additions and 0 deletions
|
@ -230,6 +230,7 @@ protected:
|
|||
// special case: deleting the only node
|
||||
if (m_size == 1) {
|
||||
m_root = nullptr;
|
||||
m_minimum = nullptr;
|
||||
m_size = 0;
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -128,3 +128,17 @@ TEST_CASE(find_smallest_not_below_iterator)
|
|||
EXPECT_EQ(smallest_not_below_three.key(), 3u);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE(iterators_on_emptied_tree)
|
||||
{
|
||||
RedBlackTree<size_t, size_t> test;
|
||||
test.insert(1, 1);
|
||||
test.remove(1);
|
||||
EXPECT_EQ(test.size(), 0u);
|
||||
auto begin_iterator = test.begin();
|
||||
auto end_iterator = test.end();
|
||||
EXPECT(begin_iterator.is_end());
|
||||
|
||||
EXPECT_EQ(begin_iterator, end_iterator);
|
||||
EXPECT(!(begin_iterator != end_iterator));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue