Fix (hopefully) part #2 of issue #117 for non-parallel hash maps

This commit is contained in:
greg
2021-11-18 21:47:59 -05:00
parent 7277c6ed23
commit 3f02d81926
+15 -5
View File
@@ -1441,6 +1441,17 @@ public:
slot_type** slot_;
};
struct fpi_result
{
~fpi_result() { if (second) set->set_ctrl(first, H2(hashval)); }
raw_hash_set *set;
size_t hashval;
size_t first;
bool second;
};
template <class K = key_type, class F>
iterator lazy_emplace(const key_arg<K>& key, F&& f) {
auto res = find_or_prepare_insert(key);
@@ -2082,7 +2093,7 @@ private:
protected:
template <class K>
std::pair<size_t, bool> find_or_prepare_insert(const K& key, size_t hashval) {
fpi_result find_or_prepare_insert(const K& key, size_t hashval) {
auto seq = probe(hashval);
while (true) {
Group g{ctrl_ + seq.offset()};
@@ -2090,16 +2101,16 @@ protected:
if (PHMAP_PREDICT_TRUE(PolicyTraits::apply(
EqualElement<K>{key, eq_ref()},
PolicyTraits::element(slots_ + seq.offset((size_t)i)))))
return {seq.offset((size_t)i), false};
return {this, hashval, seq.offset((size_t)i), false};
}
if (PHMAP_PREDICT_TRUE(g.MatchEmpty())) break;
seq.next();
}
return {prepare_insert(hashval), true};
return {this, hashval, prepare_insert(hashval), true};
}
template <class K>
std::pair<size_t, bool> find_or_prepare_insert(const K& key) {
fpi_result find_or_prepare_insert(const K& key) {
return find_or_prepare_insert(key, this->hash(key));
}
@@ -2112,7 +2123,6 @@ protected:
}
++size_;
growth_left() -= IsEmpty(ctrl_[target.offset]);
set_ctrl(target.offset, H2(hashval));
infoz_.RecordInsert(hashval, target.probe_length);
return target.offset;
}