Rotate all the way to the bottom for simplicity

This commit is contained in:
2024-05-14 18:04:35 -07:00
parent 5afe1037b2
commit a7005af6ba

View File

@@ -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<std::memory_order_relaxed>(node, false, latestVersion);
const auto r =
child<std::memory_order_relaxed>(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<std::memory_order_relaxed>(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<std::memory_order_relaxed>(finger, latestVersion, true);
#ifndef NDEBUG
if (finger.searchPathSize() > 0) {