Still need a better way identify left/right sidedness

This commit is contained in:
2024-02-09 15:17:37 -08:00
parent f3e7279c2c
commit 80a79aab1f
3 changed files with 108 additions and 19 deletions

View File

@@ -43,7 +43,7 @@ struct Node {
int16_t numChildren = 0;
bool entryPresent = false;
uint8_t parentsIndex = 0;
constexpr static auto kPartialKeyMaxLen = 10;
constexpr static auto kPartialKeyMaxLen = 26;
uint8_t partialKey[kPartialKeyMaxLen];
int8_t partialKeyLen = 0;
/* end section that's copied to the next node */
@@ -730,25 +730,37 @@ bool checkRangeRead(Node *n, const std::span<const uint8_t> begin,
while (!left.step())
;
}
if (!rightDone) {
while (!right.step())
;
}
Arena arena;
auto leftPath = vector<Node *>(arena);
auto rightPath = vector<Node *>(arena);
for (auto *iter = left.n; iter != nullptr; iter = iter->parent) {
leftPath.push_back(iter);
}
for (auto *iter = right.n; iter != nullptr; iter = iter->parent) {
rightPath.push_back(iter);
Arena arena{64 << 10};
// auto leftBorder = hashSet<Node *>(arena);
// auto rightBorder = hashSet<Node *>(arena);
auto leftBorder = vector<Node *>(arena);
auto rightBorder = vector<Node *>(arena);
{
auto *l = left.n;
auto *r = right.n;
for (; l != nullptr && r != nullptr; l = l->parent, r = r->parent) {
leftBorder.push_back(l);
rightBorder.push_back(r);
}
for (; l != nullptr; l = l->parent) {
leftBorder.push_back(l);
}
for (; r != nullptr; r = r->parent) {
rightBorder.push_back(r);
}
}
#if DEBUG_VERBOSE && !defined(NDEBUG)
fprintf(stderr, "firstGeq for `%s' got `%s'\n", printable(begin).c_str(),
getSearchPath(left.n).c_str());
getSearchPathPrintable(left.n).c_str());
fprintf(stderr, "firstGeq for `%s' got `%s'\n", printable(end).c_str(),
getSearchPath(right.n).c_str());
getSearchPathPrintable(right.n).c_str());
#endif
if (left.n != nullptr && left.cmp != 0 &&
@@ -764,12 +776,14 @@ bool checkRangeRead(Node *n, const std::span<const uint8_t> begin,
}
// TODO better data structure for pointer set. Also collect during first
// traversal.
// traversal?
for (auto *iter = nextPhysical(left.n); iter != right.n;) {
const bool onLeftPath =
std::find(leftPath.begin(), leftPath.end(), iter) != leftPath.end();
const bool onRightPath =
std::find(rightPath.begin(), rightPath.end(), iter) != rightPath.end();
// const bool onLeftPath = leftBorder.find(iter) != leftBorder.end();
// const bool onRightPath = rightBorder.find(iter) != rightBorder.end();
const bool onLeftPath = std::find(leftBorder.begin(), leftBorder.end(),
iter) != leftBorder.end();
const bool onRightPath = std::find(rightBorder.begin(), rightBorder.end(),
iter) != rightBorder.end();
if (!onLeftPath && !onRightPath) {
if (iter->maxVersion > readVersion) {
return false;