Permalink
Browse files

Hashmaps: Reset state when growing.

std::move() is by no means guaranteed to clear.
  • Loading branch information...
unknownbrackets committed Dec 2, 2017
1 parent e9a7bda commit bbb4987cc087eabb8e5fdb8979d92c29e604a7d9
Showing with 12 additions and 0 deletions.
  1. +12 −0 Common/Hashmaps.h
@@ -150,6 +150,11 @@ class DenseHashMap {
// This is extremely non-atomic and will need synchronization.
std::vector<Pair> old = std::move(map);
std::vector<BucketState> oldState = std::move(state);
// Can't assume move will clear, it just may clear.
map.clear();
state.clear();
int oldCount = count_;
capacity_ *= factor;
map.resize(capacity_);
state.resize(capacity_);
@@ -160,6 +165,7 @@ class DenseHashMap {
Insert(old[i].key, old[i].value);
}
}
_assert_msg_(SYSTEM, oldCount == count_, "DenseHashMap: count should not change in Grow()");
}
struct Pair {
Key key;
@@ -289,6 +295,11 @@ class PrehashMap {
// This is extremely non-atomic and will need synchronization.
std::vector<Pair> old = std::move(map);
std::vector<BucketState> oldState = std::move(state);
// Can't assume move will clear, it just may clear.
map.clear();
state.clear();
int oldCount = count_;
capacity_ *= factor;
map.resize(capacity_);
state.resize(capacity_);
@@ -299,6 +310,7 @@ class PrehashMap {
Insert(old[i].hash, old[i].value);
}
}
_assert_msg_(SYSTEM, oldCount == count_, "PrehashMap: count should not change in Grow()");
}
struct Pair {
uint32_t hash;

0 comments on commit bbb4987

Please sign in to comment.