Have insert return a pointer to the in-tree pointer

This commit is contained in:
2024-08-09 13:58:31 -07:00
parent a1dfdf355c
commit 2dba0d5be3

View File

@@ -2922,12 +2922,12 @@ void consumePartialKey(Node *&self, std::span<const uint8_t> &key,
key = key.subspan(partialKeyIndex, key.size() - partialKeyIndex);
}
// Returns a pointer to the newly inserted node. Caller must set
// `entryPresent`, and `entry` fields. All nodes along the search path of the
// result will have `maxVersion` set to `writeVersion` as a postcondition. Nodes
// along the search path may be invalidated.
// Returns a pointer the pointer to the newly inserted node in the tree. Caller
// must set `entryPresent`, and `entry` fields. All nodes along the search path
// of the result will have `maxVersion` set to `writeVersion` as a
// postcondition. Nodes along the search path may be invalidated.
[[nodiscard]]
Node *insert(Node **self, std::span<const uint8_t> key,
Node **insert(Node **self, std::span<const uint8_t> key,
InternalVersionT writeVersion, WriteContext *tls,
ConflictSet::Impl *impl) {
@@ -2940,7 +2940,7 @@ Node *insert(Node **self, std::span<const uint8_t> key,
for (;; ++tls->accum.insert_iterations) {
if (key.size() == 0) {
return *self;
return self;
}
auto &child = getOrCreateChild(*self, key.front(), writeVersion, tls);
@@ -2953,7 +2953,7 @@ Node *insert(Node **self, std::span<const uint8_t> key,
child->parentsIndex = key.front();
setMaxVersion(child, impl, writeVersion);
memcpy(child->partialKey(), key.data() + 1, child->partialKeyLen);
return child;
return &child;
}
self = &child;
@@ -2996,7 +2996,7 @@ void addPointWrite(Node *&root, std::span<const uint8_t> key,
InternalVersionT writeVersion, WriteContext *tls,
ConflictSet::Impl *impl) {
++tls->accum.point_writes;
auto *n = insert(&root, key, writeVersion, tls, impl);
auto *n = *insert(&root, key, writeVersion, tls, impl);
if (!n->entryPresent) {
++tls->accum.entries_inserted;
auto *p = nextLogical(n);
@@ -3097,7 +3097,7 @@ void addWriteRange(Node *&root, std::span<const uint8_t> begin,
begin = begin.subspan(consumed, begin.size() - consumed);
end = end.subspan(consumed, end.size() - consumed);
auto *beginNode = insert(useAsRoot, begin, writeVersion, tls, impl);
auto *beginNode = *insert(useAsRoot, begin, writeVersion, tls, impl);
const bool insertedBegin = !beginNode->entryPresent;
@@ -3114,7 +3114,7 @@ void addWriteRange(Node *&root, std::span<const uint8_t> begin,
assert(writeVersion >= beginNode->entry.pointVersion);
beginNode->entry.pointVersion = writeVersion;
auto *endNode = insert(useAsRoot, end, writeVersion, tls, impl);
auto *endNode = *insert(useAsRoot, end, writeVersion, tls, impl);
const bool insertedEnd = !endNode->entryPresent;
@@ -3132,7 +3132,7 @@ void addWriteRange(Node *&root, std::span<const uint8_t> begin,
if (beginIsPrefix && insertedEnd) {
// beginNode may have been invalidated when inserting end. TODO can we do
// better?
beginNode = insert(useAsRoot, begin, writeVersion, tls, impl);
beginNode = *insert(useAsRoot, begin, writeVersion, tls, impl);
assert(beginNode->entryPresent);
}