Phase enum

This commit is contained in:
2024-01-18 11:58:57 -08:00
parent 7d695fe6cf
commit b2de5c82e3

View File

@@ -389,25 +389,27 @@ struct ConflictSet::Impl {
Node *n;
Impl *impl;
int state;
enum Phase { Search, Rotate };
Phase phase;
StepwiseInsert() {}
StepwiseInsert(Node **root, const Key &key, int64_t writeVersion,
Impl *impl)
: current(root), parent(nullptr), key(&key), writeVersion(writeVersion),
impl(impl), state(0) {}
impl(impl), phase(Search) {}
bool step() {
switch (state) {
// Search
case 0: {
switch (phase) {
case Search: {
if (*current == nullptr) {
auto *newNode = createNode(*key, parent, writeVersion);
*current = newNode;
// We could interleave the iteration in next, but we'd need a careful
// analysis for correctness and it's unlikely to be worthwhile.
auto *prev = ::next(newNode, false);
assert(prev != nullptr);
assert(prev->rangeVersion <= writeVersion);
newNode->rangeVersion = prev->rangeVersion;
state = 1;
phase = Rotate;
n = *current;
return false;
} else {
@@ -418,7 +420,7 @@ struct ConflictSet::Impl {
auto c = *key <=> **current;
if (c == 0) {
(*current)->pointVersion = writeVersion;
state = 1;
phase = Rotate;
n = *current;
return false;
}
@@ -427,8 +429,7 @@ struct ConflictSet::Impl {
}
return false;
}
// Rotate
case 1: {
case Rotate: {
if (n->parent == nullptr) {
return true;
}