Skip to content

Fix bug where an item was not added to the delta view of the sharing map #4663

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/util/sharing_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,8 @@ SHARING_MAPT(void)::add_item_if_not_shared(
}
}

delta_view.push_back({k, l1.get_value()});

return;
}

Expand Down
72 changes: 36 additions & 36 deletions unit/util/sharing_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,33 +49,12 @@ void fill2(some_sharing_mapt &sm)
sm.insert("n", "5");
}

// tests

class some_keyt
{
public:
some_keyt() : s(0)
{
}

explicit some_keyt(size_t s) : s(s)
{
}

size_t s;

bool operator==(const some_keyt &other) const
{
return s == other.s;
}
};

class some_key_hasht
class key_hasht
{
public:
size_t operator()(const some_keyt &k) const
std::size_t operator()(const std::size_t &k) const
{
return k.s & 0x3;
return k & 0x3;
}
};

Expand Down Expand Up @@ -494,27 +473,48 @@ TEST_CASE("Sharing map copying", "[core][util]")

TEST_CASE("Sharing map collisions", "[core][util]")
{
typedef sharing_mapt<some_keyt, std::string, false, some_key_hasht>
typedef sharing_mapt<std::size_t, std::string, false, key_hasht>
sharing_map_collisionst;

sharing_map_collisionst sm;

sm.insert(some_keyt(0), "a");
sm.insert(some_keyt(8), "b");
sm.insert(some_keyt(16), "c");
SECTION("Basic")
{
sm.insert(0, "a");
sm.insert(8, "b");
sm.insert(16, "c");

sm.insert(some_keyt(1), "d");
sm.insert(some_keyt(2), "e");
sm.insert(1, "d");
sm.insert(2, "e");

sm.erase(some_keyt(8));
sm.erase(8);

REQUIRE(sm.has_key(some_keyt(0)));
REQUIRE(sm.has_key(some_keyt(16)));
REQUIRE(sm.has_key(0));
REQUIRE(sm.has_key(16));

REQUIRE(sm.has_key(some_keyt(1)));
REQUIRE(sm.has_key(some_keyt(2)));
REQUIRE(sm.has_key(1));
REQUIRE(sm.has_key(2));

REQUIRE(!sm.has_key(8));
}

SECTION("Delta view")
{
sm.insert(0, "a");

REQUIRE(!sm.has_key(some_keyt(8)));
sharing_map_collisionst sm2;

sm2.insert(8, "b");
sm2.insert(16, "c");

sharing_map_collisionst::delta_viewt delta_view;

sm.get_delta_view(sm2, delta_view, false);

REQUIRE(delta_view.size() == 1);
REQUIRE(delta_view[0].k == 0);
REQUIRE(!delta_view[0].is_in_both_maps());
}
}

TEST_CASE("Sharing map views and iteration", "[core][util]")
Expand Down