Commit 26262a91 authored by Xiao Shi's avatar Xiao Shi Committed by Facebook Github Bot

fix bulk erase in `F14VectorMap`

Summary:
`iterator F14VectorMap::erase(const_iterator, const_iterator)` was missing a
conversion from `const_iterator` to `iterator`. This diff adds it as well as a
test. For sets, `iterator == const_iterator` so no need for anything special.

Perhaps we could save the roundtrip from iterator space to index space and
back using some const_cast of fancy pointers? The cost is going to be amortized
anyway...

Reviewed By: nbronson

Differential Revision: D7373152

fbshipit-source-id: 91f651b3e4a1314c68fb8809baeb1477f8881790
parent 1813a644
......@@ -944,7 +944,8 @@ class F14VectorMap
while (first != last) {
first = erase(first);
}
return first;
auto index = this->table_.iterToIndex(first);
return index == 0 ? end() : this->table_.indexToIter(index - 1);
}
std::size_t erase(key_type const& key) {
......
......@@ -227,7 +227,7 @@ void runRandom() {
auto t = t0.erase(k);
auto r = r0.erase(k);
EXPECT_EQ(t, r);
} else if (pct < 50) {
} else if (pct < 47) {
// erase by iterator
if (t0.size() > 0) {
auto r = r0.find(k);
......@@ -245,6 +245,28 @@ void runRandom() {
EXPECT_NE(r->first, k);
}
}
} else if (pct < 50) {
// bulk erase
if (t0.size() > 0) {
auto r = r0.find(k);
if (r == r0.end()) {
r = r0.begin();
}
k = r->first;
auto t = t0.find(k);
auto firstt = t;
auto lastt = ++t;
t = t0.erase(firstt, lastt);
if (t != t0.end()) {
EXPECT_NE(t->first, k);
}
auto firstr = r;
auto lastr = ++r;
r = r0.erase(firstr, lastr);
if (r != r0.end()) {
EXPECT_NE(r->first, k);
}
}
} else if (pct < 58) {
// find
auto t = t0.find(k);
......
......@@ -208,7 +208,7 @@ void runRandom() {
auto t = t0.erase(k);
auto r = r0.erase(k);
EXPECT_EQ(t, r);
} else if (pct < 50) {
} else if (pct < 47) {
// erase by iterator
if (t0.size() > 0) {
auto r = r0.find(k);
......@@ -226,6 +226,28 @@ void runRandom() {
EXPECT_NE(*r, k);
}
}
} else if (pct < 50) {
// bulk erase
if (t0.size() > 0) {
auto r = r0.find(k);
if (r == r0.end()) {
r = r0.begin();
}
k = *r;
auto t = t0.find(k);
auto firstt = t;
auto lastt = ++t;
t = t0.erase(firstt, lastt);
if (t != t0.end()) {
EXPECT_NE(*t, k);
}
auto firstr = r;
auto lastr = ++r;
r = r0.erase(firstr, lastr);
if (r != r0.end()) {
EXPECT_NE(*r, k);
}
}
} else if (pct < 58) {
// find
auto t = t0.find(k);
......
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