From a7005af6ba6a6506c048ff8e11acf274fdd305d4 Mon Sep 17 00:00:00 2001 From: Andrew Noyes Date: Tue, 14 May 2024 18:04:35 -0700 Subject: [PATCH] Rotate all the way to the bottom for simplicity --- VersionedMap.cpp | 32 +++++++++----------------------- 1 file changed, 9 insertions(+), 23 deletions(-) diff --git a/VersionedMap.cpp b/VersionedMap.cpp index e009279..7481717 100644 --- a/VersionedMap.cpp +++ b/VersionedMap.cpp @@ -822,7 +822,6 @@ struct __attribute__((__visibility__("hidden"))) VersionedMap::Impl { // True if finger is pointing to an entry > than the entry we're removing // after we rotate it down - bool greaterThan; // Rotate down until we can remove the entry for (;;) { @@ -831,17 +830,13 @@ struct __attribute__((__visibility__("hidden"))) VersionedMap::Impl { child(node, false, latestVersion); const auto r = child(node, true, latestVersion); - if (l == 0) { - node = r; - greaterThan = true; - break; - } else if (r == 0) { - node = l; - greaterThan = false; + if (l == 0 && r == 0) { + // TODO we can avoid some rotations if we stop when l or r == 0 + node = 0; break; } else { - const bool direction = - mm.base[l].entry->priority > mm.base[r].entry->priority; + const bool direction = (l == 0 ? 0 : mm.base[l].entry->priority) > + (r == 0 ? 0 : mm.base[r].entry->priority); rotate(node, latestVersion, direction); assert(node != 0); finger.push( @@ -853,7 +848,8 @@ struct __attribute__((__visibility__("hidden"))) VersionedMap::Impl { // propagate up the search path, all the way to the root since we may have // more rotations to do even if an update doesn't change a node pointer auto node = finger.backNode(); - const auto oldSize = finger.searchPathSize() - (node == 0); + assert(node == 0); + const auto oldSize = finger.searchPathSize(); for (;;) { if (finger.searchPathSize() == 1) { // Made it to the root @@ -869,18 +865,8 @@ struct __attribute__((__visibility__("hidden"))) VersionedMap::Impl { } finger.setSearchPathSizeUnsafe(oldSize); - if (greaterThan && finger.backNode() != 0) { - uint32_t c; - while ((c = child(finger.backNode(), false, - latestVersion)) != 0) { - finger.push(c, false); - } - } else { - while (finger.searchPathSize() > 1 && finger.backDirection() == true) { - finger.pop(); - } - finger.pop(); - } + // finger now points to the insertion point of the node we're removing + move(finger, latestVersion, true); #ifndef NDEBUG if (finger.searchPathSize() > 0) {