diff options
author | hcpp <hcpp@ydb.tech> | 2024-03-04 17:59:20 +0300 |
---|---|---|
committer | hcpp <hcpp@ydb.tech> | 2024-03-04 18:14:12 +0300 |
commit | 187ff575305eeb34f1917a964482b3724ec546f1 (patch) | |
tree | 16854ccdbffd8dadea641d01683ba42f7c93c730 /library | |
parent | d0dca30a5b0275bcdcc2c26f672558bc5113e479 (diff) | |
download | ydb-187ff575305eeb34f1917a964482b3724ec546f1.tar.gz |
disjoint_interval_tree has been fixed for the only one interval
591efff179d61582961dbd66ad865cec1fbf9886
Diffstat (limited to 'library')
-rw-r--r-- | library/cpp/containers/disjoint_interval_tree/disjoint_interval_tree.h | 2 | ||||
-rw-r--r-- | library/cpp/containers/disjoint_interval_tree/ut/disjoint_interval_tree_ut.cpp | 12 |
2 files changed, 13 insertions, 1 deletions
diff --git a/library/cpp/containers/disjoint_interval_tree/disjoint_interval_tree.h b/library/cpp/containers/disjoint_interval_tree/disjoint_interval_tree.h index 3f51c61277..f0c6644d4b 100644 --- a/library/cpp/containers/disjoint_interval_tree/disjoint_interval_tree.h +++ b/library/cpp/containers/disjoint_interval_tree/disjoint_interval_tree.h @@ -132,7 +132,7 @@ public: } TIterator completelyRemoveEnd = completelyRemoveBegin != Tree.end() ? Tree.lower_bound(end) : Tree.end(); - if (completelyRemoveEnd != Tree.end() && completelyRemoveEnd != Tree.begin() && completelyRemoveEnd->first != end) { + if (completelyRemoveEnd != Tree.begin() && (completelyRemoveEnd == Tree.end() || completelyRemoveEnd->first != end)) { TIterator containingEnd = completelyRemoveEnd; --containingEnd; if (containingEnd->second > end) { diff --git a/library/cpp/containers/disjoint_interval_tree/ut/disjoint_interval_tree_ut.cpp b/library/cpp/containers/disjoint_interval_tree/ut/disjoint_interval_tree_ut.cpp index 8474ae89b0..508a82459a 100644 --- a/library/cpp/containers/disjoint_interval_tree/ut/disjoint_interval_tree_ut.cpp +++ b/library/cpp/containers/disjoint_interval_tree/ut/disjoint_interval_tree_ut.cpp @@ -232,6 +232,18 @@ Y_UNIT_TEST_SUITE(DisjointIntervalTreeTest) { UNIT_ASSERT_VALUES_EQUAL(tree.GetNumIntervals(), 2); UNIT_ASSERT_VALUES_EQUAL(tree.GetNumElements(), 8); } + + // 12. The only one interval + { + TDisjointIntervalTree<ui64> tree; + tree.InsertInterval(1, 10); + UNIT_ASSERT_VALUES_EQUAL(tree.GetNumIntervals(), 1); + UNIT_ASSERT_VALUES_EQUAL(tree.GetNumElements(), 9); + UNIT_ASSERT_VALUES_EQUAL(tree.EraseInterval(0, 6), 5); + UNIT_ASSERT_VALUES_EQUAL(tree.GetNumIntervals(), 1); + UNIT_ASSERT_VALUES_EQUAL(tree.GetNumElements(), 4); + UNIT_ASSERT(tree.Intersects(5, 10)); + } } Y_UNIT_TEST(IntersectsTest) { |