Shuffle keys before inserting
This commit is contained in:
@@ -3,13 +3,14 @@
|
||||
#include <cassert>
|
||||
#include <compare>
|
||||
#include <memory>
|
||||
#include <random>
|
||||
#include <span>
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#define SHOW_PRIORITY 1
|
||||
#define DEBUG 1
|
||||
#define SHOW_PRIORITY 0
|
||||
#define DEBUG 0
|
||||
|
||||
using Key = ConflictSet::Key;
|
||||
|
||||
@@ -527,6 +528,13 @@ struct ConflictSet::Impl {
|
||||
|
||||
// TODO Descend until queries for front and back diverge
|
||||
|
||||
// Mitigate potential n^2 behavior of insertion by shuffling the insertion
|
||||
// order. Not sure how this interacts with interleaved insertion but it's
|
||||
// probably fine.
|
||||
// TODO better/faster RNG?
|
||||
std::mt19937 g(fastRand());
|
||||
std::shuffle(stepwiseInserts.get(), stepwiseInserts.get() + count, g);
|
||||
|
||||
runInterleaved(std::span<StepwiseInsert>(stepwiseInserts.get(), count));
|
||||
|
||||
std::vector<Node *> workList;
|
||||
@@ -538,6 +546,10 @@ struct ConflictSet::Impl {
|
||||
while (!workList.empty()) {
|
||||
Node *n = workList.back();
|
||||
workList.pop_back();
|
||||
#if DEBUG
|
||||
fprintf(stderr, "\tcheck heap invariant %.*s\n", n->len,
|
||||
(const char *)(n + 1));
|
||||
#endif
|
||||
if (n->parent == nullptr) {
|
||||
continue;
|
||||
}
|
||||
@@ -561,8 +573,6 @@ struct ConflictSet::Impl {
|
||||
if (lr != nullptr) {
|
||||
workList.push_back(lr);
|
||||
}
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -621,7 +631,7 @@ ConflictSet &ConflictSet::operator=(ConflictSet &&other) noexcept {
|
||||
int main(void) {
|
||||
int64_t writeVersion = 0;
|
||||
ConflictSet::Impl cs{writeVersion};
|
||||
constexpr int kNumKeys = 3;
|
||||
constexpr int kNumKeys = 5;
|
||||
ConflictSet::WriteRange write[kNumKeys];
|
||||
for (int i = 0; i < kNumKeys; ++i) {
|
||||
write[i].begin = toKey(i);
|
||||
|
Reference in New Issue
Block a user