From eb96833eb02330ab28f31e9eab95894c9445ece6 Mon Sep 17 00:00:00 2001 From: Andrew Noyes Date: Thu, 15 Feb 2024 17:20:25 -0800 Subject: [PATCH] Use sparse scan under a threshold --- ConflictSet.cpp | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/ConflictSet.cpp b/ConflictSet.cpp index 61fc5fc..392ce3e 100644 --- a/ConflictSet.cpp +++ b/ConflictSet.cpp @@ -741,6 +741,7 @@ int64_t maxBetweenExclusive(Node *n, int begin, int end) { assert(end <= 256); assert(begin < end); int64_t result = std::numeric_limits::lowest(); + constexpr int kSparseThreshold = 32; { int c = getChildGeq(n, begin + 1); if (c >= 0 && c < end) { @@ -771,19 +772,35 @@ int64_t maxBetweenExclusive(Node *n, int begin, int end) { } case Type::Node48: { auto *self = static_cast(n); - for (int i = begin + 1; i < end; ++i) { - if (self->index[i] != -1) { - result = std::max(result, self->children[self->index[i]]->maxVersion); + if (self->numChildren < kSparseThreshold) { + for (int i = self->bitSet.firstSetGeq(begin + 1); i < end && i >= 0; + i = self->bitSet.firstSetGeq(i + 1)) { + if (self->index[i] != -1) { + result = std::max(result, self->children[self->index[i]]->maxVersion); + } + } + } else { + for (int i = begin + 1; i < end; ++i) { + if (self->index[i] != -1) { + result = std::max(result, self->children[self->index[i]]->maxVersion); + } } } break; } case Type::Node256: { auto *self = static_cast(n); - for (int i = begin + 1; i < end; ++i) { - if (self->children[i] != nullptr) { + if (self->numChildren < kSparseThreshold) { + for (int i = self->bitSet.firstSetGeq(begin + 1); i < end && i >= 0; + i = self->bitSet.firstSetGeq(i + 1)) { result = std::max(result, self->children[i]->maxVersion); } + } else { + for (int i = begin + 1; i < end; ++i) { + if (self->children[i] != nullptr) { + result = std::max(result, self->children[i]->maxVersion); + } + } } break; }