Rename erase_and_unshift() to erase_or_unshift()
This commit is contained in:
parent
b81c950056
commit
f051337cd3
|
@ -191,7 +191,7 @@ void CollectionChangeBuilder::insert(size_t index, size_t count)
|
|||
void CollectionChangeBuilder::erase(size_t index)
|
||||
{
|
||||
modifications.erase_at(index);
|
||||
size_t unshifted = insertions.erase_and_unshift(index);
|
||||
size_t unshifted = insertions.erase_or_unshift(index);
|
||||
if (unshifted != npos)
|
||||
deletions.add_shifted(unshifted);
|
||||
|
||||
|
@ -247,7 +247,7 @@ void CollectionChangeBuilder::move(size_t from, size_t to)
|
|||
}
|
||||
|
||||
if (!updated_existing_move) {
|
||||
auto shifted_from = insertions.erase_and_unshift(from);
|
||||
auto shifted_from = insertions.erase_or_unshift(from);
|
||||
insertions.insert_at(to);
|
||||
|
||||
// Don't report deletions/moves for newly inserted rows
|
||||
|
@ -316,7 +316,7 @@ void CollectionChangeBuilder::move_over(size_t row_ndx, size_t last_row)
|
|||
return;
|
||||
|
||||
// Don't report deletions/moves if last_row is newly inserted
|
||||
auto shifted_last_row = insertions.erase_and_unshift(last_row);
|
||||
auto shifted_last_row = insertions.erase_or_unshift(last_row);
|
||||
if (shifted_last_row != npos) {
|
||||
shifted_last_row = deletions.add_shifted(shifted_last_row);
|
||||
moves.push_back({shifted_last_row, row_ndx});
|
||||
|
|
|
@ -295,7 +295,7 @@ void IndexSet::erase_at(IndexSet const& positions)
|
|||
add_back(*begin1 - shift);
|
||||
}
|
||||
|
||||
size_t IndexSet::erase_and_unshift(size_t index)
|
||||
size_t IndexSet::erase_or_unshift(size_t index)
|
||||
{
|
||||
auto shifted = index;
|
||||
auto it = m_ranges.begin(), end = m_ranges.end();
|
||||
|
|
|
@ -76,7 +76,8 @@ public:
|
|||
void erase_at(size_t index);
|
||||
void erase_at(IndexSet const&);
|
||||
|
||||
size_t erase_and_unshift(size_t index);
|
||||
// If the given index is in the set remove it and return npos; otherwise unshift() it
|
||||
size_t erase_or_unshift(size_t index);
|
||||
|
||||
// Remove the indexes at the given index from the set, without shifting
|
||||
void remove(size_t index, size_t count=1);
|
||||
|
|
|
@ -408,34 +408,34 @@ TEST_CASE("[index_set] erase_at()") {
|
|||
}
|
||||
}
|
||||
|
||||
TEST_CASE("[index_set] erase_and_unshfit()") {
|
||||
TEST_CASE("[index_set] erase_or_unshift()") {
|
||||
realm::IndexSet set;
|
||||
|
||||
SECTION("removes the given index") {
|
||||
set = {1, 2};
|
||||
set.erase_and_unshift(2);
|
||||
set.erase_or_unshift(2);
|
||||
REQUIRE_INDICES(set, 1);
|
||||
}
|
||||
|
||||
SECTION("shifts indexes after the given index") {
|
||||
set = {1, 5};
|
||||
set.erase_and_unshift(2);
|
||||
set.erase_or_unshift(2);
|
||||
REQUIRE_INDICES(set, 1, 4);
|
||||
}
|
||||
|
||||
SECTION("returns npos for indices in the set") {
|
||||
set = {1, 3, 5};
|
||||
REQUIRE(realm::IndexSet(set).erase_and_unshift(1) == realm::IndexSet::npos);
|
||||
REQUIRE(realm::IndexSet(set).erase_and_unshift(3) == realm::IndexSet::npos);
|
||||
REQUIRE(realm::IndexSet(set).erase_and_unshift(5) == realm::IndexSet::npos);
|
||||
REQUIRE(realm::IndexSet(set).erase_or_unshift(1) == realm::IndexSet::npos);
|
||||
REQUIRE(realm::IndexSet(set).erase_or_unshift(3) == realm::IndexSet::npos);
|
||||
REQUIRE(realm::IndexSet(set).erase_or_unshift(5) == realm::IndexSet::npos);
|
||||
}
|
||||
|
||||
SECTION("returns the number of indices in the set before the index for ones not in the set") {
|
||||
set = {1, 3, 5, 6};
|
||||
REQUIRE(realm::IndexSet(set).erase_and_unshift(0) == 0);
|
||||
REQUIRE(realm::IndexSet(set).erase_and_unshift(2) == 1);
|
||||
REQUIRE(realm::IndexSet(set).erase_and_unshift(4) == 2);
|
||||
REQUIRE(realm::IndexSet(set).erase_and_unshift(7) == 3);
|
||||
REQUIRE(realm::IndexSet(set).erase_or_unshift(0) == 0);
|
||||
REQUIRE(realm::IndexSet(set).erase_or_unshift(2) == 1);
|
||||
REQUIRE(realm::IndexSet(set).erase_or_unshift(4) == 2);
|
||||
REQUIRE(realm::IndexSet(set).erase_or_unshift(7) == 3);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue