Commit 66a6916f authored by Nick Terrell's avatar Nick Terrell Committed by Facebook Github Bot

ConcurrentHashMap set size and max_size.

Summary:
During move construction and assignment `size_` and `max_size_` aren't set.
Added a test case that attempted to allocate 4096 GB before the patch, and passes after.

Reviewed By: yfeldblum

Differential Revision: D7005041

fbshipit-source-id: b42a0a408ce49ddded4ba805fc064cd11df2457e
parent 996729ec
......@@ -126,7 +126,8 @@ class ConcurrentHashMap {
}
}
ConcurrentHashMap(ConcurrentHashMap&& o) noexcept {
ConcurrentHashMap(ConcurrentHashMap&& o) noexcept
: size_(o.size_), max_size_(o.max_size_) {
for (uint64_t i = 0; i < NumShards; i++) {
segments_[i].store(
o.segments_[i].load(std::memory_order_relaxed),
......@@ -147,6 +148,8 @@ class ConcurrentHashMap {
std::memory_order_relaxed);
o.segments_[i].store(nullptr, std::memory_order_relaxed);
}
size_ = o.size_;
max_size_ = o.max_size_;
return *this;
}
......
......@@ -249,6 +249,19 @@ TEST(ConcurrentHashMap, MapIterateTest) {
EXPECT_EQ(count, 2);
}
TEST(ConcurrentHashMap, MoveIterateAssignIterate) {
using Map = ConcurrentHashMap<int, int>;
Map tmp;
Map map{std::move(tmp)};
map.insert(0, 0);
++map.cbegin();
ConcurrentHashMap<int, int> other;
other.insert(0, 0);
map = std::move(other);
++map.cbegin();
}
TEST(ConcurrentHashMap, EraseTest) {
ConcurrentHashMap<uint64_t, uint64_t> foomap(3);
foomap.insert(1, 0);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment