Re-use search implementation in insert
This commit is contained in:
@@ -587,18 +587,18 @@ struct __attribute__((__visibility__("hidden"))) VersionedMap::Impl {
|
|||||||
int len;
|
int len;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Initialize finger to the insertion path of `key`. If `key` is not present,
|
||||||
|
// then the finger ends on a null entry.
|
||||||
template <std::memory_order kOrder, class T>
|
template <std::memory_order kOrder, class T>
|
||||||
void search(Key key, T root, int64_t version, Finger &finger) const {
|
void search(Key key, T root, int64_t version, Finger &finger) const {
|
||||||
// Prevent integer promotion etc
|
// Prevent integer promotion etc
|
||||||
static_assert(std::is_same_v<T, uint32_t>);
|
static_assert(std::is_same_v<T, uint32_t>);
|
||||||
|
|
||||||
finger.clear();
|
finger.clear();
|
||||||
if (root == 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
bool ignored;
|
bool ignored;
|
||||||
finger.push(root, ignored);
|
finger.push(root, ignored);
|
||||||
|
|
||||||
// Initialize finger to the search path of `key`
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
auto n = finger.backNode();
|
auto n = finger.backNode();
|
||||||
if (n == 0) {
|
if (n == 0) {
|
||||||
@@ -617,27 +617,9 @@ struct __attribute__((__visibility__("hidden"))) VersionedMap::Impl {
|
|||||||
// Otherwise it's the end of a range mutation at `latestVersion`.
|
// Otherwise it's the end of a range mutation at `latestVersion`.
|
||||||
// `finger` becomes the search path of `key`
|
// `finger` becomes the search path of `key`
|
||||||
void insert(Key key, std::optional<Val> val, Finger &finger) {
|
void insert(Key key, std::optional<Val> val, Finger &finger) {
|
||||||
bool ignored;
|
|
||||||
finger.clear();
|
|
||||||
finger.push(latestRoot, ignored);
|
|
||||||
bool inserted;
|
|
||||||
|
|
||||||
// Initialize finger to the search path of `key`
|
search<std::memory_order_relaxed>(key, latestRoot, latestVersion, finger);
|
||||||
for (;;) {
|
const bool inserted = finger.backNode() == 0;
|
||||||
auto n = finger.backNode();
|
|
||||||
if (n == 0) {
|
|
||||||
inserted = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
auto c = key <=> mm.base[n];
|
|
||||||
if (c == 0) {
|
|
||||||
// No duplicates
|
|
||||||
inserted = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
finger.push(child<std::memory_order_relaxed>(n, c > 0, latestVersion),
|
|
||||||
c > 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
int64_t pointVersion, rangeVersion;
|
int64_t pointVersion, rangeVersion;
|
||||||
if (val.has_value()) {
|
if (val.has_value()) {
|
||||||
|
Reference in New Issue
Block a user