Bring back nextSibling

This commit is contained in:
2024-02-09 15:26:54 -08:00
parent 80a79aab1f
commit d1ee3d8b69

View File

@@ -512,10 +512,23 @@ struct Iterator {
int cmp;
};
Node *nextSibling(Node *node) {
for (;;) {
if (node->parent == nullptr) {
return nullptr;
}
auto next = getChildGeq(node->parent, node->parentsIndex + 1);
if (next < 0) {
node = node->parent;
} else {
return getChildExists(node->parent, next);
}
}
}
struct FirstGeqStepwise {
Node *n;
std::span<const uint8_t> remaining;
Node *nextSib = nullptr;
int cmp;
enum Phase {
@@ -541,10 +554,6 @@ struct FirstGeqStepwise {
return downLeftSpine();
} else {
int c = getChildGeq(n, remaining[0]);
int c2 = getChildGeq(n, int(remaining[0]) + 1);
if (c2 >= 0) {
nextSib = getChildExists(n, c2);
}
if (c == remaining[0]) {
n = getChildExists(n, c);
remaining = remaining.subspan(1, remaining.size() - 1);
@@ -553,7 +562,7 @@ struct FirstGeqStepwise {
n = getChildExists(n, c);
return downLeftSpine();
} else {
n = nextSib;
n = nextSibling(n);
return downLeftSpine();
}
}
@@ -571,7 +580,7 @@ struct FirstGeqStepwise {
if (c > 0) {
return downLeftSpine();
} else {
n = nextSib;
n = nextSibling(n);
return downLeftSpine();
}
}
@@ -628,7 +637,6 @@ Iterator firstGeq(Node *n, const std::span<const uint8_t> key) {
bool checkPointRead(Node *n, const std::span<const uint8_t> key,
int64_t readVersion) {
auto remaining = key;
Node *nextSib = nullptr;
for (;;) {
if (n->partialKeyLen > 0) {
int commonLen = std::min<int>(n->partialKeyLen, remaining.size());
@@ -640,7 +648,7 @@ bool checkPointRead(Node *n, const std::span<const uint8_t> key,
if (c > 0) {
goto downLeftSpine;
} else {
n = nextSib;
n = nextSibling(n);
goto downLeftSpine;
}
}
@@ -666,10 +674,6 @@ bool checkPointRead(Node *n, const std::span<const uint8_t> key,
goto downLeftSpine;
} else {
int c = getChildGeq(n, remaining[0]);
int c2 = getChildGeq(n, int(remaining[0]) + 1);
if (c2 >= 0) {
nextSib = getChildExists(n, c2);
}
if (c == remaining[0]) {
n = getChildExists(n, c);
remaining = remaining.subspan(1, remaining.size() - 1);
@@ -678,7 +682,7 @@ bool checkPointRead(Node *n, const std::span<const uint8_t> key,
n = getChildExists(n, c);
goto downLeftSpine;
} else {
n = nextSib;
n = nextSibling(n);
goto downLeftSpine;
}
}