AK: Clear minimum when removing last node of RedBlackTree

This commit is contained in:
davidot 2022-02-10 12:24:49 +01:00 committed by Linus Groh
parent 2bddf157b1
commit fdbfe85a87
Notes: sideshowbarker 2024-07-17 19:03:20 +09:00
2 changed files with 15 additions and 0 deletions

View file

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

View file

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