From f9364b50a4385b631521315d9a25ef4da845a02d Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Mon, 2 May 2016 16:24:54 -0700 Subject: [PATCH] Return the correct iterator from ChunkedVector::erase() When a chunk is removed entirely it should return an iterator to the first element in the next chunk, not the last. --- src/index_set.cpp | 2 +- tests/index_set.cpp | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/index_set.cpp b/src/index_set.cpp index b9b9525c..2c566e13 100644 --- a/src/index_set.cpp +++ b/src/index_set.cpp @@ -151,7 +151,7 @@ ChunkedRangeVector::iterator ChunkedRangeVector::erase(iterator pos) if (chunk.data.size() == 0) { pos.m_outer = m_data.erase(pos.m_outer); pos.m_end = m_data.end(); - pos.m_inner = pos.m_outer == m_data.end() ? nullptr : &pos.m_outer->data.back(); + pos.m_inner = pos.m_outer == m_data.end() ? nullptr : &pos.m_outer->data.front(); verify(); return pos; } diff --git a/tests/index_set.cpp b/tests/index_set.cpp index df5af2f1..ff62a05d 100644 --- a/tests/index_set.cpp +++ b/tests/index_set.cpp @@ -120,6 +120,17 @@ TEST_CASE("[index_set] add()") { set.add(i); REQUIRE_INDICES(set, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20); } + + SECTION("merges ranges even when they are in different chunks") { + realm::IndexSet set2; + for (int i = 0; i < 20; ++i) { + set.add(i * 2); + set2.add(i); + set2.add(i * 2); + } + set.add(set2); + REQUIRE(set.count() == 30); + } } TEST_CASE("[index_set] add_shifted()") {