From c9b35241e1e67e0122be109a3e59e56ed3f9907c Mon Sep 17 00:00:00 2001 From: Andrew Noyes Date: Wed, 14 Feb 2024 12:05:33 -0800 Subject: [PATCH] Factor out "maxRightOf" --- ConflictSet.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/ConflictSet.cpp b/ConflictSet.cpp index 5af9107..5f29b5d 100644 --- a/ConflictSet.cpp +++ b/ConflictSet.cpp @@ -919,6 +919,16 @@ descend(int &depth, int &lcp, Node *newNode, std::span 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::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 begin, const std::span end, int64_t readVersion, Arena &arena) { @@ -1039,11 +1049,8 @@ bool checkRangeRead(Node *n, const std::span 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);