2020-04-15 04:16:28 +08:00
|
|
|
#include "fdbclient/VersionedMap.h"
|
|
|
|
#include "flow/TreeBenchmark.h"
|
|
|
|
#include "flow/UnitTest.h"
|
|
|
|
|
|
|
|
template <typename K>
|
|
|
|
struct VersionedMapHarness {
|
|
|
|
using map = VersionedMap<K, int>;
|
|
|
|
using key_type = K;
|
|
|
|
|
|
|
|
struct result {
|
|
|
|
typename map::iterator it;
|
|
|
|
|
|
|
|
result(typename map::iterator it) : it(it) {}
|
|
|
|
|
|
|
|
result& operator++() {
|
|
|
|
++it;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
const K& operator*() const { return it.key(); }
|
|
|
|
|
|
|
|
const K& operator->() const { return it.key(); }
|
|
|
|
|
|
|
|
bool operator==(result const& k) const { return it == k.it; }
|
2020-07-11 05:37:47 +08:00
|
|
|
bool operator!=(result const& k) const { return !(*this == k); }
|
2020-04-15 04:16:28 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
map s;
|
|
|
|
|
|
|
|
void insert(K const& k) { s.insert(k, 1); }
|
|
|
|
result find(K const& k) const { return result(s.atLatest().find(k)); }
|
|
|
|
result not_found() const { return result(s.atLatest().end()); }
|
|
|
|
result begin() const { return result(s.atLatest().begin()); }
|
|
|
|
result end() const { return result(s.atLatest().end()); }
|
|
|
|
result lower_bound(K const& k) const { return result(s.atLatest().lower_bound(k)); }
|
|
|
|
result upper_bound(K const& k) const { return result(s.atLatest().upper_bound(k)); }
|
|
|
|
void erase(K const& k) { s.erase(k); }
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_CASE("performance/map/int/VersionedMap") {
|
2021-03-11 02:06:03 +08:00
|
|
|
VersionedMapHarness<int> tree;
|
2020-04-15 04:16:28 +08:00
|
|
|
|
|
|
|
treeBenchmark(tree, *randomInt);
|
|
|
|
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE("performance/map/StringRef/VersionedMap") {
|
|
|
|
Arena arena;
|
2021-03-11 02:06:03 +08:00
|
|
|
VersionedMapHarness<StringRef> tree;
|
|
|
|
|
2020-04-15 04:16:28 +08:00
|
|
|
treeBenchmark(tree, [&arena]() { return randomStr(arena); });
|
|
|
|
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
|
|
|
void forceLinkVersionedMapTests() {}
|