Simplify firstGeq - make it not stepwise
All checks were successful
Tests / Release [gcc] total: 704, passed: 704
GNU C Compiler (gcc) |Total|New|Outstanding|Fixed|Trend |:-:|:-:|:-:|:-:|:-: |0|0|0|0|:clap: Reference build: <a href="https://jenkins.weaselab.dev/job/weaselab/job/conflict-set/job/main/66//gcc">weaselab » conflict-set » main #66</a>
Tests / Release [gcc,aarch64] total: 703, passed: 703
Tests / Coverage total: 702, passed: 702
weaselab/conflict-set/pipeline/head This commit looks good

This commit is contained in:
2024-03-07 16:05:38 -08:00
parent 8a36e72640
commit a8042ab20d

View File

@@ -1741,32 +1741,17 @@ void addWriteRange(Node *&root, int64_t oldestVersion,
} }
} }
struct FirstGeqStepwise { Iterator firstGeq(Node *n, const std::span<const uint8_t> key) {
Node *n; auto remaining = key;
std::span<const uint8_t> remaining; for (;;) {
int cmp;
enum Phase {
Init,
// Being in this phase implies that the key matches the search path exactly
// up to this point
Search,
DownLeftSpine
};
Phase phase;
FirstGeqStepwise(Node *n, std::span<const uint8_t> remaining)
: n(n), remaining(remaining), phase(Init) {}
// Not being done implies that n is not the firstGeq
bool step() {
switch (phase) {
case Search: {
if (remaining.size() == 0) { if (remaining.size() == 0) {
if (n->entryPresent) {
return {n, 0};
}
int c = getChildGeq(n, 0); int c = getChildGeq(n, 0);
assert(c >= 0); assert(c >= 0);
n = getChildExists(n, c); n = getChildExists(n, c);
return downLeftSpine(); goto downLeftSpine;
} }
auto *child = getChild(n, remaining[0]); auto *child = getChild(n, remaining[0]);
@@ -1774,10 +1759,10 @@ struct FirstGeqStepwise {
int c = getChildGeq(n, remaining[0]); int c = getChildGeq(n, remaining[0]);
if (c >= 0) { if (c >= 0) {
n = getChildExists(n, c); n = getChildExists(n, c);
return downLeftSpine(); goto downLeftSpine;
} else { } else {
n = nextSibling(n); n = nextSibling(n);
return downLeftSpine(); goto downLeftSpine;
} }
} }
@@ -1791,59 +1776,34 @@ struct FirstGeqStepwise {
if (i < commonLen) { if (i < commonLen) {
auto c = n->partialKey[i] <=> remaining[i]; auto c = n->partialKey[i] <=> remaining[i];
if (c > 0) { if (c > 0) {
return downLeftSpine(); goto downLeftSpine;
} else { } else {
n = nextSibling(n); n = nextSibling(n);
return downLeftSpine(); goto downLeftSpine;
} }
} }
if (commonLen == n->partialKeyLen) { if (commonLen == n->partialKeyLen) {
// partial key matches // partial key matches
remaining = remaining = remaining.subspan(commonLen, remaining.size() - commonLen);
remaining.subspan(commonLen, remaining.size() - commonLen);
} else if (n->partialKeyLen > int(remaining.size())) { } else if (n->partialKeyLen > int(remaining.size())) {
// n is the first physical node greater than remaining, and there's no // n is the first physical node greater than remaining, and there's no
// eq node // eq node
return downLeftSpine(); goto downLeftSpine;
} }
} }
} }
[[fallthrough]]; downLeftSpine:
case Init: if (n == nullptr) {
phase = Search; return {nullptr, 1};
if (remaining.size() == 0 && n->entryPresent) { }
cmp = 0; for (;;) {
return true; if (n->entryPresent) {
return {n, 1};
} }
return false;
case DownLeftSpine:
int c = getChildGeq(n, 0); int c = getChildGeq(n, 0);
assert(c >= 0); assert(c >= 0);
n = getChildExists(n, c); n = getChildExists(n, c);
if (n->entryPresent) {
cmp = 1;
return true;
} }
return false;
}
__builtin_unreachable(); // GCOVR_EXCL_LINE
}
bool downLeftSpine() {
phase = DownLeftSpine;
if (n == nullptr || n->entryPresent) {
cmp = 1;
return true;
}
return step();
}
};
Iterator firstGeq(Node *n, const std::span<const uint8_t> key) {
FirstGeqStepwise stepwise{n, key};
while (!stepwise.step())
;
return {stepwise.n, stepwise.cmp};
} }
struct __attribute__((visibility("hidden"))) ConflictSet::Impl { struct __attribute__((visibility("hidden"))) ConflictSet::Impl {