From d1ee3d8b69de5a0fc4d8e4047c229d37708d7d58 Mon Sep 17 00:00:00 2001 From: Andrew Noyes Date: Fri, 9 Feb 2024 15:26:54 -0800 Subject: [PATCH] Bring back nextSibling --- ConflictSet.cpp | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/ConflictSet.cpp b/ConflictSet.cpp index e167e28..ae844da 100644 --- a/ConflictSet.cpp +++ b/ConflictSet.cpp @@ -512,10 +512,23 @@ struct Iterator { int cmp; }; +Node *nextSibling(Node *node) { + for (;;) { + if (node->parent == nullptr) { + return nullptr; + } + auto next = getChildGeq(node->parent, node->parentsIndex + 1); + if (next < 0) { + node = node->parent; + } else { + return getChildExists(node->parent, next); + } + } +} + struct FirstGeqStepwise { Node *n; std::span remaining; - Node *nextSib = nullptr; int cmp; enum Phase { @@ -541,10 +554,6 @@ struct FirstGeqStepwise { return downLeftSpine(); } else { int c = getChildGeq(n, remaining[0]); - int c2 = getChildGeq(n, int(remaining[0]) + 1); - if (c2 >= 0) { - nextSib = getChildExists(n, c2); - } if (c == remaining[0]) { n = getChildExists(n, c); remaining = remaining.subspan(1, remaining.size() - 1); @@ -553,7 +562,7 @@ struct FirstGeqStepwise { n = getChildExists(n, c); return downLeftSpine(); } else { - n = nextSib; + n = nextSibling(n); return downLeftSpine(); } } @@ -571,7 +580,7 @@ struct FirstGeqStepwise { if (c > 0) { return downLeftSpine(); } else { - n = nextSib; + n = nextSibling(n); return downLeftSpine(); } } @@ -628,7 +637,6 @@ Iterator firstGeq(Node *n, const std::span key) { bool checkPointRead(Node *n, const std::span key, int64_t readVersion) { auto remaining = key; - Node *nextSib = nullptr; for (;;) { if (n->partialKeyLen > 0) { int commonLen = std::min(n->partialKeyLen, remaining.size()); @@ -640,7 +648,7 @@ bool checkPointRead(Node *n, const std::span key, if (c > 0) { goto downLeftSpine; } else { - n = nextSib; + n = nextSibling(n); goto downLeftSpine; } } @@ -666,10 +674,6 @@ bool checkPointRead(Node *n, const std::span key, goto downLeftSpine; } else { int c = getChildGeq(n, remaining[0]); - int c2 = getChildGeq(n, int(remaining[0]) + 1); - if (c2 >= 0) { - nextSib = getChildExists(n, c2); - } if (c == remaining[0]) { n = getChildExists(n, c); remaining = remaining.subspan(1, remaining.size() - 1); @@ -678,7 +682,7 @@ bool checkPointRead(Node *n, const std::span key, n = getChildExists(n, c); goto downLeftSpine; } else { - n = nextSib; + n = nextSibling(n); goto downLeftSpine; } }