Factor out "maxRightOf"

This commit is contained in:
2024-02-14 12:05:33 -08:00
parent c131398af6
commit c9b35241e1

View File

@@ -919,6 +919,16 @@ descend(int &depth, int &lcp, Node *newNode, std::span<const uint8_t> end,
newNode->partialKey + newNode->partialKeyLen);
}
// Precondition: node has a child at index begin
int64_t maxRightOf(Node *n, int begin) {
int64_t result = std::numeric_limits<int64_t>::lowest();
while (begin >= 0) {
result = std::max(result, getChildExists(n, begin)->maxVersion);
begin = getChildGeq(n, begin + 1);
}
return result;
}
bool checkRangeRead(Node *n, const std::span<const uint8_t> begin,
const std::span<const uint8_t> end, int64_t readVersion,
Arena &arena) {
@@ -1039,11 +1049,8 @@ bool checkRangeRead(Node *n, const std::span<const uint8_t> begin,
fprintf(stderr, "%s, right of %02x\n",
printable(searchPath).c_str(), next);
#endif
while (next >= 0) {
if (getChildExists(iter, next)->maxVersion > readVersion) {
return false;
}
next = getChildGeq(iter, next + 1);
if (maxRightOf(iter, next) > readVersion) {
return false;
}
} else {
iter = getChildExists(iter, next);