Move addWriteRange into its own function
This commit is contained in:
@@ -1393,6 +1393,56 @@ void destroyTree(Node *root) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void addWriteRange(Node *&root, int64_t oldestVersion,
|
||||||
|
const ConflictSet::WriteRange &w) {
|
||||||
|
|
||||||
|
auto *begin = insert(&root, std::span<const uint8_t>(w.begin.p, w.begin.len),
|
||||||
|
w.writeVersion, true);
|
||||||
|
|
||||||
|
const bool insertedBegin = !std::exchange(begin->entryPresent, true);
|
||||||
|
|
||||||
|
if (insertedBegin) {
|
||||||
|
auto *p = nextLogical(begin);
|
||||||
|
begin->entry.rangeVersion =
|
||||||
|
p != nullptr ? p->entry.rangeVersion : oldestVersion;
|
||||||
|
begin->entry.pointVersion = w.writeVersion;
|
||||||
|
begin->maxVersion = w.writeVersion;
|
||||||
|
}
|
||||||
|
begin->maxVersion = std::max(begin->maxVersion, w.writeVersion);
|
||||||
|
begin->entry.pointVersion =
|
||||||
|
std::max(begin->entry.pointVersion, w.writeVersion);
|
||||||
|
|
||||||
|
auto *end = insert(&root, std::span<const uint8_t>(w.end.p, w.end.len),
|
||||||
|
w.writeVersion, false);
|
||||||
|
|
||||||
|
const bool insertedEnd = !std::exchange(end->entryPresent, true);
|
||||||
|
|
||||||
|
if (insertedEnd) {
|
||||||
|
auto *p = nextLogical(end);
|
||||||
|
end->entry.pointVersion =
|
||||||
|
p != nullptr ? p->entry.rangeVersion : oldestVersion;
|
||||||
|
end->maxVersion = std::max(end->maxVersion, end->entry.pointVersion);
|
||||||
|
}
|
||||||
|
end->entry.rangeVersion = w.writeVersion;
|
||||||
|
|
||||||
|
if (insertedEnd) {
|
||||||
|
// begin may have been invalidated
|
||||||
|
auto iter =
|
||||||
|
firstGeq(root, std::span<const uint8_t>(w.begin.p, w.begin.len));
|
||||||
|
assert(iter.cmp == 0);
|
||||||
|
begin = iter.n;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (begin = nextLogical(begin); begin != end;) {
|
||||||
|
auto *old = begin;
|
||||||
|
begin = nextLogical(begin);
|
||||||
|
old->entryPresent = false;
|
||||||
|
if (old->numChildren == 0 && old->parent != nullptr) {
|
||||||
|
eraseChild(old->parent, old->parentsIndex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct __attribute__((visibility("hidden"))) ConflictSet::Impl {
|
struct __attribute__((visibility("hidden"))) ConflictSet::Impl {
|
||||||
|
|
||||||
void check(const ReadRange *reads, Result *result, int count) const {
|
void check(const ReadRange *reads, Result *result, int count) const {
|
||||||
@@ -1420,52 +1470,7 @@ struct __attribute__((visibility("hidden"))) ConflictSet::Impl {
|
|||||||
for (int i = 0; i < count; ++i) {
|
for (int i = 0; i < count; ++i) {
|
||||||
const auto &w = writes[i];
|
const auto &w = writes[i];
|
||||||
if (w.end.len > 0) {
|
if (w.end.len > 0) {
|
||||||
auto *begin =
|
addWriteRange(root, oldestVersion, w);
|
||||||
insert(&root, std::span<const uint8_t>(w.begin.p, w.begin.len),
|
|
||||||
w.writeVersion, true);
|
|
||||||
|
|
||||||
const bool insertedBegin = !std::exchange(begin->entryPresent, true);
|
|
||||||
|
|
||||||
if (insertedBegin) {
|
|
||||||
auto *p = nextLogical(begin);
|
|
||||||
begin->entry.rangeVersion =
|
|
||||||
p != nullptr ? p->entry.rangeVersion : oldestVersion;
|
|
||||||
begin->entry.pointVersion = w.writeVersion;
|
|
||||||
begin->maxVersion = w.writeVersion;
|
|
||||||
}
|
|
||||||
begin->maxVersion = std::max(begin->maxVersion, w.writeVersion);
|
|
||||||
begin->entry.pointVersion =
|
|
||||||
std::max(begin->entry.pointVersion, w.writeVersion);
|
|
||||||
|
|
||||||
auto *end = insert(&root, std::span<const uint8_t>(w.end.p, w.end.len),
|
|
||||||
w.writeVersion, false);
|
|
||||||
|
|
||||||
const bool insertedEnd = !std::exchange(end->entryPresent, true);
|
|
||||||
|
|
||||||
if (insertedEnd) {
|
|
||||||
auto *p = nextLogical(end);
|
|
||||||
end->entry.pointVersion =
|
|
||||||
p != nullptr ? p->entry.rangeVersion : oldestVersion;
|
|
||||||
end->maxVersion = std::max(end->maxVersion, end->entry.pointVersion);
|
|
||||||
}
|
|
||||||
end->entry.rangeVersion = w.writeVersion;
|
|
||||||
|
|
||||||
if (insertedEnd) {
|
|
||||||
// begin may have been invalidated
|
|
||||||
auto iter =
|
|
||||||
firstGeq(root, std::span<const uint8_t>(w.begin.p, w.begin.len));
|
|
||||||
assert(iter.cmp == 0);
|
|
||||||
begin = iter.n;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (begin = nextLogical(begin); begin != end;) {
|
|
||||||
auto *old = begin;
|
|
||||||
begin = nextLogical(begin);
|
|
||||||
old->entryPresent = false;
|
|
||||||
if (old->numChildren == 0 && old->parent != nullptr) {
|
|
||||||
eraseChild(old->parent, old->parentsIndex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
auto *n =
|
auto *n =
|
||||||
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),
|
||||||
|
Reference in New Issue
Block a user