This commit is contained in:
2024-01-18 10:42:29 -08:00
parent 8c15cb28d0
commit 1497f4f890

View File

@@ -247,10 +247,10 @@ void lastLeqMulti(Node *root, std::span<Key> keys, Iterator *results) {
fprintf(file, "\n");
for (auto iter = extrema(node, false); iter != nullptr;
iter = next(iter, true)) {
fprintf(file, " k_%.*s [label=\"k=%.*s;m=%d;v=%d,r=%d\"];\n", iter->len,
(const char *)(iter + 1), iter->len, (const char *)(iter + 1),
int(iter->maxVersion), int(iter->pointVersion),
int(iter->rangeVersion));
fprintf(file, " k_%.*s [label=\"k=\\\"%.*s\\\" m=%d v=%d r=%d\"];\n",
iter->len, (const char *)(iter + 1), iter->len,
(const char *)(iter + 1), int(iter->maxVersion),
int(iter->pointVersion), int(iter->rangeVersion));
}
for (int i = 0; i < printer.id; ++i) {
fprintf(file, " null%d [shape=point];\n", i);
@@ -357,7 +357,6 @@ struct ConflictSet::Impl {
Node **current = &root;
Node *parent = nullptr;
const auto &key = write.begin;
bool inserted = false;
for (;;) {
if (*current == nullptr) {
auto *newNode = createNode(key, parent, write.writeVersion);
@@ -366,7 +365,6 @@ struct ConflictSet::Impl {
assert(prev != nullptr);
assert(prev->rangeVersion <= write.writeVersion);
newNode->rangeVersion = prev->rangeVersion;
inserted = true;
break;
} else {
// This is the key optimization - setting the max version on the way
@@ -382,27 +380,26 @@ struct ConflictSet::Impl {
current = &((*current)->child[c > 0]);
}
}
if (inserted) {
auto *n = *current;
assert(n != nullptr);
for (;;) {
if (n->parent == nullptr) {
break;
}
const bool dir = n == n->parent->child[1];
assert(dir || n == n->parent->child[0]);
// p is the address of the pointer to n->parent in the tree
Node **p = n->parent->parent == nullptr
? &root
: &n->parent->parent
->child[n->parent->parent->child[1] == n->parent];
assert(*p == n->parent);
if (n->parent->priority < n->priority) {
p = rotate(p, !dir);
n = (*p)->parent;
} else {
break;
}
auto *n = *current;
assert(n != nullptr);
for (;;) {
if (n->parent == nullptr) {
break;
}
const bool dir = n == n->parent->child[1];
assert(dir || n == n->parent->child[0]);
// p is the address of the pointer to n->parent in the tree
Node **p = n->parent->parent == nullptr
? &root
: &n->parent->parent
->child[n->parent->parent->child[1] == n->parent];
assert(*p == n->parent);
if (n->parent->priority < n->priority) {
p = rotate(p, !dir);
n = (*p)->parent;
} else {
break;
}
}
}
@@ -465,12 +462,13 @@ ConflictSet &ConflictSet::operator=(ConflictSet &&other) noexcept {
#ifdef ENABLE_TESTS
int main(void) {
ConflictSet::Impl cs{0};
int64_t writeVersion = 0;
ConflictSet::Impl cs{writeVersion};
for (int i = 0; i < 10; ++i) {
ConflictSet::WriteRange write;
write.begin = toKey(i);
write.end.len = 0;
write.writeVersion = i;
write.writeVersion = ++writeVersion;
cs.addWrites(&write, 1);
}
debugPrintDot(stdout, cs.root);