Skip to content

Commit 179a3cb

Browse files
cherry pick library fix (#2481)
1 parent 7444062 commit 179a3cb

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

library/cpp/containers/disjoint_interval_tree/disjoint_interval_tree.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ class TDisjointIntervalTree {
132132
}
133133

134134
TIterator completelyRemoveEnd = completelyRemoveBegin != Tree.end() ? Tree.lower_bound(end) : Tree.end();
135-
if (completelyRemoveEnd != Tree.end() && completelyRemoveEnd != Tree.begin() && completelyRemoveEnd->first != end) {
135+
if (completelyRemoveEnd != Tree.begin() && (completelyRemoveEnd == Tree.end() || completelyRemoveEnd->first != end)) {
136136
TIterator containingEnd = completelyRemoveEnd;
137137
--containingEnd;
138138
if (containingEnd->second > end) {

library/cpp/containers/disjoint_interval_tree/ut/disjoint_interval_tree_ut.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,18 @@ Y_UNIT_TEST_SUITE(DisjointIntervalTreeTest) {
232232
UNIT_ASSERT_VALUES_EQUAL(tree.GetNumIntervals(), 2);
233233
UNIT_ASSERT_VALUES_EQUAL(tree.GetNumElements(), 8);
234234
}
235+
236+
// 12. The only one interval
237+
{
238+
TDisjointIntervalTree<ui64> tree;
239+
tree.InsertInterval(1, 10);
240+
UNIT_ASSERT_VALUES_EQUAL(tree.GetNumIntervals(), 1);
241+
UNIT_ASSERT_VALUES_EQUAL(tree.GetNumElements(), 9);
242+
UNIT_ASSERT_VALUES_EQUAL(tree.EraseInterval(0, 6), 5);
243+
UNIT_ASSERT_VALUES_EQUAL(tree.GetNumIntervals(), 1);
244+
UNIT_ASSERT_VALUES_EQUAL(tree.GetNumElements(), 4);
245+
UNIT_ASSERT(tree.Intersects(5, 10));
246+
}
235247
}
236248

237249
Y_UNIT_TEST(IntersectsTest) {

0 commit comments

Comments
 (0)