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