forked from weaselab/conflict-set
Use sparse scan under a threshold
This commit is contained in:
+22
-5
@@ -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<int64_t>::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<Node48 *>(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<Node256 *>(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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user