Simplify and fix bugs
This commit is contained in:
@@ -27,7 +27,7 @@ int compare(std::span<const uint8_t> lhs, std::span<const uint8_t> rhs) {
|
||||
if (c != 0) {
|
||||
return c;
|
||||
}
|
||||
return int(rhs.size()) - int(lhs.size());
|
||||
return int(lhs.size()) - int(rhs.size());
|
||||
}
|
||||
|
||||
std::span<uint8_t> strincMutate(std::span<uint8_t> str, bool &ok) {
|
||||
@@ -774,74 +774,50 @@ bool checkRangeRead(Node *n, const std::span<const uint8_t> begin,
|
||||
const std::span<const uint8_t> end, int64_t readVersion,
|
||||
Arena &arena) {
|
||||
auto left = FirstGeqStepwise{n, begin};
|
||||
auto right = FirstGeqStepwise{n, end};
|
||||
bool leftDone = left.step();
|
||||
bool rightDone = right.step();
|
||||
if (!leftDone && !rightDone) {
|
||||
for (;;) {
|
||||
if (left.phase == FirstGeqStepwise::Search &&
|
||||
right.phase == FirstGeqStepwise::Search &&
|
||||
left.n->maxVersion <= readVersion) {
|
||||
return true;
|
||||
}
|
||||
leftDone = left.step();
|
||||
rightDone = right.step();
|
||||
if (leftDone || rightDone) {
|
||||
break;
|
||||
}
|
||||
if (left.n != right.n) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!leftDone) {
|
||||
while (!left.step())
|
||||
;
|
||||
}
|
||||
|
||||
if (!rightDone) {
|
||||
while (!right.step())
|
||||
;
|
||||
}
|
||||
while (!left.step())
|
||||
;
|
||||
|
||||
#if DEBUG_VERBOSE && !defined(NDEBUG)
|
||||
fprintf(stderr, "firstGeq for `%s' got `%s'\n", printable(begin).c_str(),
|
||||
getSearchPathPrintable(left.n).c_str());
|
||||
fprintf(stderr, "firstGeq for `%s' got `%s'\n", printable(end).c_str(),
|
||||
getSearchPathPrintable(right.n).c_str());
|
||||
#endif
|
||||
|
||||
if (left.n != nullptr && left.cmp != 0 &&
|
||||
left.n->entry.rangeVersion > readVersion) {
|
||||
return false;
|
||||
}
|
||||
if (left.n == right.n) {
|
||||
if (left.n == nullptr) {
|
||||
return true;
|
||||
}
|
||||
assert(left.n != nullptr);
|
||||
if (left.n->entry.pointVersion > readVersion) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto searchPath = getSearchPath(arena, left.n);
|
||||
|
||||
for (auto *iter = nextPhysical(left.n, searchPath); iter != right.n;) {
|
||||
assert(searchPath == getSearchPath(arena, iter));
|
||||
if (iter->entryPresent && iter->entry.rangeVersion > readVersion) {
|
||||
return false;
|
||||
if (left.cmp != 0 && left.n->entry.rangeVersion > readVersion) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool first = true;
|
||||
for (auto *iter = left.n; iter != nullptr && compare(searchPath, end) < 0;
|
||||
first = false) {
|
||||
if (iter->entryPresent) {
|
||||
if (!first && iter->entry.rangeVersion > readVersion) {
|
||||
return false;
|
||||
}
|
||||
if (iter->entry.pointVersion > readVersion) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
bool ok = true;
|
||||
|
||||
assert(searchPath == getSearchPath(arena, iter));
|
||||
#if DEBUG_VERBOSE && !defined(NDEBUG)
|
||||
fprintf(stderr, "Max version of keys starting with %s: %" PRId64 "\n",
|
||||
printable(searchPath).c_str(), iter->maxVersion);
|
||||
#endif
|
||||
bool ok = true;
|
||||
auto rangeEnd = strincMutate(searchPath, ok);
|
||||
int c;
|
||||
if (!ok) {
|
||||
return iter->maxVersion <= readVersion;
|
||||
goto iterate;
|
||||
}
|
||||
int c = compare(rangeEnd, end);
|
||||
c = compare(rangeEnd, end);
|
||||
--rangeEnd.back();
|
||||
|
||||
if (c == 0) {
|
||||
return iter->maxVersion <= readVersion;
|
||||
} else if (c < 0) {
|
||||
@@ -850,6 +826,7 @@ bool checkRangeRead(Node *n, const std::span<const uint8_t> begin,
|
||||
}
|
||||
iter = nextSibling(iter, searchPath);
|
||||
} else {
|
||||
iterate:
|
||||
if (iter->maxVersion <= readVersion) {
|
||||
return true;
|
||||
}
|
||||
|
Reference in New Issue
Block a user