From f3e7279c2c18b16e4059737470f60317fe74dde2 Mon Sep 17 00:00:00 2001 From: Andrew Noyes Date: Fri, 9 Feb 2024 13:08:14 -0800 Subject: [PATCH] Do less work --- ConflictSet.cpp | 33 ++++++++++----------------------- 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/ConflictSet.cpp b/ConflictSet.cpp index 61c7a24..049b95f 100644 --- a/ConflictSet.cpp +++ b/ConflictSet.cpp @@ -744,31 +744,11 @@ bool checkRangeRead(Node *n, const std::span begin, for (auto *iter = right.n; iter != nullptr; iter = iter->parent) { rightPath.push_back(iter); } - std::reverse(leftPath.begin(), leftPath.end()); - std::reverse(rightPath.begin(), rightPath.end()); - Node *lca = n; - int longestCommonPrefixSize = 0; - for (int i = 0, end = std::min(leftPath.size(), rightPath.size()); - i < end; ++i, ++longestCommonPrefixSize) { - if (leftPath[i] != rightPath[i]) { - break; - } - lca = leftPath[i]; - } - auto border = vector(arena); - for (int i = longestCommonPrefixSize; i < int(leftPath.size()); ++i) { - border.push_back(leftPath[i]); - } - for (int i = longestCommonPrefixSize; i < int(rightPath.size()); ++i) { - border.push_back(rightPath[i]); - } - #if DEBUG_VERBOSE && !defined(NDEBUG) fprintf(stderr, "firstGeq for `%s' got `%s'\n", printable(begin).c_str(), getSearchPath(left.n).c_str()); fprintf(stderr, "firstGeq for `%s' got `%s'\n", printable(end).c_str(), getSearchPath(right.n).c_str()); - fprintf(stderr, "lca `%s'\n", getSearchPath(lca).c_str()); #endif if (left.n != nullptr && left.cmp != 0 && @@ -783,15 +763,22 @@ bool checkRangeRead(Node *n, const std::span begin, return false; } - // TODO make it sublinear + // TODO better data structure for pointer set. Also collect during first + // traversal. for (auto *iter = nextPhysical(left.n); iter != right.n;) { - assert(iter != lca); - if (std::find(border.begin(), border.end(), iter) == border.end()) { + const bool onLeftPath = + std::find(leftPath.begin(), leftPath.end(), iter) != leftPath.end(); + const bool onRightPath = + std::find(rightPath.begin(), rightPath.end(), iter) != rightPath.end(); + if (!onLeftPath && !onRightPath) { if (iter->maxVersion > readVersion) { return false; } iter = nextPhysicalSkipSubtree(iter); } else { + if (onRightPath && iter->maxVersion <= readVersion) { + return true; + } if (iter->entryPresent && std::max(iter->entry.pointVersion, iter->entry.rangeVersion) > readVersion) {