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.
This commit is contained in:
Thomas Goyne 2016-05-02 16:24:54 -07:00
parent 4df552ba2d
commit f9364b50a4
2 changed files with 12 additions and 1 deletions

View File

@ -151,7 +151,7 @@ ChunkedRangeVector::iterator ChunkedRangeVector::erase(iterator pos)
if (chunk.data.size() == 0) { if (chunk.data.size() == 0) {
pos.m_outer = m_data.erase(pos.m_outer); pos.m_outer = m_data.erase(pos.m_outer);
pos.m_end = m_data.end(); 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(); verify();
return pos; return pos;
} }

View File

@ -120,6 +120,17 @@ TEST_CASE("[index_set] add()") {
set.add(i); set.add(i);
REQUIRE_INDICES(set, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20); 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()") { TEST_CASE("[index_set] add_shifted()") {