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; Node *n;
Impl *impl; Impl *impl;
int state; enum Phase { Search, Rotate };
Phase phase;
StepwiseInsert() {} StepwiseInsert() {}
StepwiseInsert(Node **root, const Key &key, int64_t writeVersion, StepwiseInsert(Node **root, const Key &key, int64_t writeVersion,
Impl *impl) Impl *impl)
: current(root), parent(nullptr), key(&key), writeVersion(writeVersion), : current(root), parent(nullptr), key(&key), writeVersion(writeVersion),
impl(impl), state(0) {} impl(impl), phase(Search) {}
bool step() { bool step() {
switch (state) { switch (phase) {
// Search case Search: {
case 0: {
if (*current == nullptr) { if (*current == nullptr) {
auto *newNode = createNode(*key, parent, writeVersion); auto *newNode = createNode(*key, parent, writeVersion);
*current = newNode; *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); auto *prev = ::next(newNode, false);
assert(prev != nullptr); assert(prev != nullptr);
assert(prev->rangeVersion <= writeVersion); assert(prev->rangeVersion <= writeVersion);
newNode->rangeVersion = prev->rangeVersion; newNode->rangeVersion = prev->rangeVersion;
state = 1; phase = Rotate;
n = *current; n = *current;
return false; return false;
} else { } else {
@@ -418,7 +420,7 @@ struct ConflictSet::Impl {
auto c = *key <=> **current; auto c = *key <=> **current;
if (c == 0) { if (c == 0) {
(*current)->pointVersion = writeVersion; (*current)->pointVersion = writeVersion;
state = 1; phase = Rotate;
n = *current; n = *current;
return false; return false;
} }
@@ -427,8 +429,7 @@ struct ConflictSet::Impl {
} }
return false; return false;
} }
// Rotate case Rotate: {
case 1: {
if (n->parent == nullptr) { if (n->parent == nullptr) {
return true; return true;
} }