Non-recursive insert
This commit is contained in:
@@ -905,22 +905,26 @@ void debugPrintDot(FILE *file, Node *node) {
|
||||
fprintf(file, "}\n");
|
||||
}
|
||||
|
||||
static Node *insert(Node *&self, std::span<const uint8_t> key,
|
||||
int64_t writeVersion) {
|
||||
self->maxVersion = writeVersion;
|
||||
if (key.size() == 0) {
|
||||
self->entryPresent = true;
|
||||
self->entry.pointVersion = writeVersion;
|
||||
// TODO set correct rangeVersion
|
||||
return self;
|
||||
static void insert(Node **self_, std::span<const uint8_t> key,
|
||||
int64_t writeVersion) {
|
||||
for (;;) {
|
||||
auto &self = *self_;
|
||||
self->maxVersion = writeVersion;
|
||||
if (key.size() == 0) {
|
||||
self->entryPresent = true;
|
||||
self->entry.pointVersion = writeVersion;
|
||||
// TODO set correct rangeVersion
|
||||
return;
|
||||
}
|
||||
auto &child = getOrCreateChild(self, key.front());
|
||||
if (!child) {
|
||||
child = newNode();
|
||||
child->parent = self;
|
||||
child->parentsIndex = key.front();
|
||||
}
|
||||
self_ = &child;
|
||||
key = key.subspan(1, key.size() - 1);
|
||||
}
|
||||
auto &child = getOrCreateChild(self, key.front());
|
||||
if (!child) {
|
||||
child = newNode();
|
||||
child->parent = self;
|
||||
child->parentsIndex = key.front();
|
||||
}
|
||||
return insert(child, key.subspan(1, key.size() - 1), writeVersion);
|
||||
}
|
||||
|
||||
struct __attribute__((visibility("hidden"))) ConflictSet::Impl {
|
||||
@@ -930,7 +934,7 @@ struct __attribute__((visibility("hidden"))) ConflictSet::Impl {
|
||||
const auto &w = writes[i];
|
||||
// TODO support non-point writes
|
||||
assert(w.end.len == 0);
|
||||
insert(root, std::span<const uint8_t>(w.begin.p, w.begin.len),
|
||||
insert(&root, std::span<const uint8_t>(w.begin.p, w.begin.len),
|
||||
w.writeVersion);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user