Remove "Child" struct
This commit is contained in:
105
ConflictSet.cpp
105
ConflictSet.cpp
@@ -236,10 +236,6 @@ constexpr int kNodeCopyBegin = offsetof(Node, entry);
|
||||
constexpr int kNodeCopySize =
|
||||
offsetof(Node, parentsIndex) + sizeof(Node::parentsIndex) - kNodeCopyBegin;
|
||||
|
||||
struct Child {
|
||||
Node *child;
|
||||
};
|
||||
|
||||
// copyChildrenAndKeyFrom is responsible for copying all
|
||||
// public members of Node, copying the partial key, logically copying the
|
||||
// children (converting representation if necessary), and updating all the
|
||||
@@ -261,7 +257,7 @@ struct Node3 : Node {
|
||||
constexpr static auto kType = Type_Node3;
|
||||
// Sorted
|
||||
uint8_t index[kMaxNodes];
|
||||
Child children[kMaxNodes];
|
||||
Node *children[kMaxNodes];
|
||||
int64_t childMaxVersion[kMaxNodes];
|
||||
uint8_t *partialKey() { return (uint8_t *)(this + 1); }
|
||||
|
||||
@@ -277,7 +273,7 @@ struct Node16 : Node {
|
||||
constexpr static auto kMaxNodes = 16;
|
||||
// Sorted
|
||||
uint8_t index[kMaxNodes];
|
||||
Child children[kMaxNodes];
|
||||
Node *children[kMaxNodes];
|
||||
int64_t childMaxVersion[kMaxNodes];
|
||||
uint8_t *partialKey() { return (uint8_t *)(this + 1); }
|
||||
|
||||
@@ -294,7 +290,7 @@ struct Node48 : Node {
|
||||
BitSet bitSet;
|
||||
int8_t nextFree;
|
||||
int8_t index[256];
|
||||
Child children[kMaxNodes];
|
||||
Node *children[kMaxNodes];
|
||||
int64_t childMaxVersion[kMaxNodes];
|
||||
uint8_t reverseIndex[kMaxNodes];
|
||||
constexpr static int kMaxOfMaxPageSize = 8;
|
||||
@@ -315,7 +311,7 @@ struct Node48 : Node {
|
||||
struct Node256 : Node {
|
||||
constexpr static auto kType = Type_Node256;
|
||||
BitSet bitSet;
|
||||
Child children[256];
|
||||
Node *children[256];
|
||||
int64_t childMaxVersion[256];
|
||||
constexpr static int kMaxOfMaxPageSize = 8;
|
||||
constexpr static int kMaxOfMaxShift =
|
||||
@@ -353,8 +349,8 @@ inline void Node3::copyChildrenAndKeyFrom(const Node3 &other) {
|
||||
memcpy(index, other.index, sizeof(*this) - sizeof(Node));
|
||||
memcpy(partialKey(), &other + 1, partialKeyLen);
|
||||
for (int i = 0; i < numChildren; ++i) {
|
||||
assert(children[i].child->parent == &other);
|
||||
children[i].child->parent = this;
|
||||
assert(children[i]->parent == &other);
|
||||
children[i]->parent = this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -362,13 +358,13 @@ inline void Node3::copyChildrenAndKeyFrom(const Node16 &other) {
|
||||
memcpy((char *)this + kNodeCopyBegin, (char *)&other + kNodeCopyBegin,
|
||||
kNodeCopySize);
|
||||
memcpy(index, other.index, kMaxNodes);
|
||||
memcpy(children, other.children, kMaxNodes * sizeof(children[0]));
|
||||
memcpy(children, other.children, kMaxNodes * sizeof(children[0])); // NOLINT
|
||||
memcpy(childMaxVersion, other.childMaxVersion,
|
||||
kMaxNodes * sizeof(childMaxVersion[0]));
|
||||
memcpy(partialKey(), &other + 1, partialKeyLen);
|
||||
for (int i = 0; i < numChildren; ++i) {
|
||||
assert(children[i].child->parent == &other);
|
||||
children[i].child->parent = this;
|
||||
assert(children[i]->parent == &other);
|
||||
children[i]->parent = this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -376,14 +372,15 @@ inline void Node16::copyChildrenAndKeyFrom(const Node3 &other) {
|
||||
memcpy((char *)this + kNodeCopyBegin, (char *)&other + kNodeCopyBegin,
|
||||
kNodeCopySize);
|
||||
memcpy(index, other.index, Node3::kMaxNodes);
|
||||
memcpy(children, other.children, Node3::kMaxNodes * sizeof(children[0]));
|
||||
memcpy(children, other.children,
|
||||
Node3::kMaxNodes * sizeof(children[0])); // NOLINT
|
||||
memcpy(childMaxVersion, other.childMaxVersion,
|
||||
Node3::kMaxNodes * sizeof(childMaxVersion[0]));
|
||||
memcpy(partialKey(), &other + 1, partialKeyLen);
|
||||
assert(numChildren == Node3::kMaxNodes);
|
||||
for (int i = 0; i < Node3::kMaxNodes; ++i) {
|
||||
assert(children[i].child->parent == &other);
|
||||
children[i].child->parent = this;
|
||||
assert(children[i]->parent == &other);
|
||||
children[i]->parent = this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -394,8 +391,8 @@ inline void Node16::copyChildrenAndKeyFrom(const Node16 &other) {
|
||||
for (int i = 0; i < numChildren; ++i) {
|
||||
children[i] = other.children[i];
|
||||
childMaxVersion[i] = other.childMaxVersion[i];
|
||||
assert(children[i].child->parent == &other);
|
||||
children[i].child->parent = this;
|
||||
assert(children[i]->parent == &other);
|
||||
children[i]->parent = this;
|
||||
}
|
||||
memcpy(partialKey(), &other + 1, partialKeyLen);
|
||||
}
|
||||
@@ -412,8 +409,8 @@ inline void Node16::copyChildrenAndKeyFrom(const Node48 &other) {
|
||||
index[i] = c;
|
||||
children[i] = other.children[other.index[c]];
|
||||
childMaxVersion[i] = other.childMaxVersion[other.index[c]];
|
||||
assert(children[i].child->parent == &other);
|
||||
children[i].child->parent = this;
|
||||
assert(children[i]->parent == &other);
|
||||
children[i]->parent = this;
|
||||
++i;
|
||||
},
|
||||
0, 256);
|
||||
@@ -436,8 +433,8 @@ inline void Node48::copyChildrenAndKeyFrom(const Node16 &other) {
|
||||
index[x] = i;
|
||||
children[i] = other.children[i];
|
||||
childMaxVersion[i] = other.childMaxVersion[i];
|
||||
assert(children[i].child->parent == &other);
|
||||
children[i].child->parent = this;
|
||||
assert(children[i]->parent == &other);
|
||||
children[i]->parent = this;
|
||||
reverseIndex[i] = x;
|
||||
maxOfMax[i >> Node48::kMaxOfMaxShift] =
|
||||
std::max(maxOfMax[i >> Node48::kMaxOfMaxShift], childMaxVersion[i]);
|
||||
@@ -456,8 +453,8 @@ inline void Node48::copyChildrenAndKeyFrom(const Node48 &other) {
|
||||
for (int i = 0; i < numChildren; ++i) {
|
||||
children[i] = other.children[i];
|
||||
childMaxVersion[i] = other.childMaxVersion[i];
|
||||
assert(children[i].child->parent == &other);
|
||||
children[i].child->parent = this;
|
||||
assert(children[i]->parent == &other);
|
||||
children[i]->parent = this;
|
||||
}
|
||||
memcpy(reverseIndex, other.reverseIndex, sizeof(reverseIndex));
|
||||
memcpy(maxOfMax, other.maxOfMax, sizeof(maxOfMax));
|
||||
@@ -481,8 +478,8 @@ inline void Node48::copyChildrenAndKeyFrom(const Node256 &other) {
|
||||
index[c] = i;
|
||||
children[i] = other.children[c];
|
||||
childMaxVersion[i] = other.childMaxVersion[c];
|
||||
assert(children[i].child->parent == &other);
|
||||
children[i].child->parent = this;
|
||||
assert(children[i]->parent == &other);
|
||||
children[i]->parent = this;
|
||||
reverseIndex[i] = c;
|
||||
maxOfMax[i >> Node48::kMaxOfMaxShift] =
|
||||
std::max(maxOfMax[i >> Node48::kMaxOfMaxShift], childMaxVersion[i]);
|
||||
@@ -503,8 +500,8 @@ inline void Node256::copyChildrenAndKeyFrom(const Node48 &other) {
|
||||
[&](int c) {
|
||||
children[c] = other.children[other.index[c]];
|
||||
childMaxVersion[c] = other.childMaxVersion[other.index[c]];
|
||||
assert(children[c].child->parent == &other);
|
||||
children[c].child->parent = this;
|
||||
assert(children[c]->parent == &other);
|
||||
children[c]->parent = this;
|
||||
maxOfMax[c >> Node256::kMaxOfMaxShift] = std::max(
|
||||
maxOfMax[c >> Node256::kMaxOfMaxShift], childMaxVersion[c]);
|
||||
},
|
||||
@@ -522,8 +519,8 @@ inline void Node256::copyChildrenAndKeyFrom(const Node256 &other) {
|
||||
[&](int c) {
|
||||
children[c] = other.children[c];
|
||||
childMaxVersion[c] = other.childMaxVersion[c];
|
||||
assert(children[c].child->parent == &other);
|
||||
children[c].child->parent = this;
|
||||
assert(children[c]->parent == &other);
|
||||
children[c]->parent = this;
|
||||
},
|
||||
0, 256);
|
||||
memcpy(maxOfMax, other.maxOfMax, sizeof(maxOfMax));
|
||||
@@ -769,21 +766,21 @@ Node *&getChildExists(Node *self, uint8_t index) {
|
||||
__builtin_unreachable(); // GCOVR_EXCL_LINE
|
||||
case Type_Node3: {
|
||||
auto *self3 = static_cast<Node3 *>(self);
|
||||
return self3->children[getNodeIndex(self3, index)].child;
|
||||
return self3->children[getNodeIndex(self3, index)];
|
||||
}
|
||||
case Type_Node16: {
|
||||
auto *self16 = static_cast<Node16 *>(self);
|
||||
return self16->children[getNodeIndex(self16, index)].child;
|
||||
return self16->children[getNodeIndex(self16, index)];
|
||||
}
|
||||
case Type_Node48: {
|
||||
auto *self48 = static_cast<Node48 *>(self);
|
||||
assert(self48->bitSet.test(index));
|
||||
return self48->children[self48->index[index]].child;
|
||||
return self48->children[self48->index[index]];
|
||||
}
|
||||
case Type_Node256: {
|
||||
auto *self256 = static_cast<Node256 *>(self);
|
||||
assert(self256->bitSet.test(index));
|
||||
return self256->children[index].child;
|
||||
return self256->children[index];
|
||||
}
|
||||
default: // GCOVR_EXCL_LINE
|
||||
__builtin_unreachable(); // GCOVR_EXCL_LINE
|
||||
@@ -803,21 +800,21 @@ Node *getChild(Node *self, uint8_t index) {
|
||||
case Type_Node3: {
|
||||
auto *self3 = static_cast<Node3 *>(self);
|
||||
int i = getNodeIndex(self3, index);
|
||||
return i < 0 ? nullptr : self3->children[i].child;
|
||||
return i < 0 ? nullptr : self3->children[i];
|
||||
}
|
||||
case Type_Node16: {
|
||||
auto *self16 = static_cast<Node16 *>(self);
|
||||
int i = getNodeIndex(self16, index);
|
||||
return i < 0 ? nullptr : self16->children[i].child;
|
||||
return i < 0 ? nullptr : self16->children[i];
|
||||
}
|
||||
case Type_Node48: {
|
||||
auto *self48 = static_cast<Node48 *>(self);
|
||||
int i = self48->index[index];
|
||||
return i < 0 ? nullptr : self48->children[i].child;
|
||||
return i < 0 ? nullptr : self48->children[i];
|
||||
}
|
||||
case Type_Node256: {
|
||||
auto *self256 = static_cast<Node256 *>(self);
|
||||
return self256->children[index].child;
|
||||
return self256->children[index];
|
||||
}
|
||||
default: // GCOVR_EXCL_LINE
|
||||
__builtin_unreachable(); // GCOVR_EXCL_LINE
|
||||
@@ -933,26 +930,26 @@ Node *&getOrCreateChild(Node *&self, uint8_t index,
|
||||
auto *self3 = static_cast<Node3 *>(self);
|
||||
int i = getNodeIndex(self3, index);
|
||||
if (i >= 0) {
|
||||
return self3->children[i].child;
|
||||
return self3->children[i];
|
||||
}
|
||||
} break;
|
||||
case Type_Node16: {
|
||||
auto *self16 = static_cast<Node16 *>(self);
|
||||
int i = getNodeIndex(self16, index);
|
||||
if (i >= 0) {
|
||||
return self16->children[i].child;
|
||||
return self16->children[i];
|
||||
}
|
||||
} break;
|
||||
case Type_Node48: {
|
||||
auto *self48 = static_cast<Node48 *>(self);
|
||||
int secondIndex = self48->index[index];
|
||||
if (secondIndex >= 0) {
|
||||
return self48->children[secondIndex].child;
|
||||
return self48->children[secondIndex];
|
||||
}
|
||||
} break;
|
||||
case Type_Node256: {
|
||||
auto *self256 = static_cast<Node256 *>(self);
|
||||
if (auto &result = self256->children[index].child; result != nullptr) {
|
||||
if (auto &result = self256->children[index]; result != nullptr) {
|
||||
return result;
|
||||
}
|
||||
} break;
|
||||
@@ -990,7 +987,8 @@ Node *&getOrCreateChild(Node *&self, uint8_t index,
|
||||
memmove(self3->index + i + 1, self3->index + i,
|
||||
self->numChildren - (i + 1));
|
||||
memmove(self3->children + i + 1, self3->children + i,
|
||||
(self->numChildren - (i + 1)) * sizeof(self3->children[0]));
|
||||
(self->numChildren - (i + 1)) *
|
||||
sizeof(self3->children[0])); // NOLINT
|
||||
memmove(self3->childMaxVersion + i + 1, self3->childMaxVersion + i,
|
||||
(self->numChildren - (i + 1)) *
|
||||
sizeof(self3->childMaxVersion[0]));
|
||||
@@ -998,7 +996,7 @@ Node *&getOrCreateChild(Node *&self, uint8_t index,
|
||||
}
|
||||
}
|
||||
self3->index[i] = index;
|
||||
auto &result = self3->children[i].child;
|
||||
auto &result = self3->children[i];
|
||||
result = nullptr;
|
||||
return result;
|
||||
}
|
||||
@@ -1053,7 +1051,8 @@ Node *&getOrCreateChild(Node *&self, uint8_t index,
|
||||
memmove(self16->index + i + 1, self16->index + i,
|
||||
self->numChildren - (i + 1));
|
||||
memmove(self16->children + i + 1, self16->children + i,
|
||||
(self->numChildren - (i + 1)) * sizeof(self16->children[0]));
|
||||
(self->numChildren - (i + 1)) *
|
||||
sizeof(self16->children[0])); // NOLINT
|
||||
memmove(self16->childMaxVersion + i + 1, self16->childMaxVersion + i,
|
||||
(self->numChildren - (i + 1)) *
|
||||
sizeof(self16->childMaxVersion[0]));
|
||||
@@ -1074,7 +1073,7 @@ Node *&getOrCreateChild(Node *&self, uint8_t index,
|
||||
}
|
||||
#endif
|
||||
self16->index[i] = index;
|
||||
auto &result = self16->children[i].child;
|
||||
auto &result = self16->children[i];
|
||||
result = nullptr;
|
||||
return result;
|
||||
}
|
||||
@@ -1097,7 +1096,7 @@ Node *&getOrCreateChild(Node *&self, uint8_t index,
|
||||
int nextFree = self48->nextFree++;
|
||||
self48->index[index] = nextFree;
|
||||
self48->reverseIndex[nextFree] = index;
|
||||
auto &result = self48->children[nextFree].child;
|
||||
auto &result = self48->children[nextFree];
|
||||
result = nullptr;
|
||||
return result;
|
||||
}
|
||||
@@ -1107,7 +1106,7 @@ Node *&getOrCreateChild(Node *&self, uint8_t index,
|
||||
auto *self256 = static_cast<Node256 *>(self);
|
||||
++self->numChildren;
|
||||
self256->bitSet.set(index);
|
||||
return self256->children[index].child;
|
||||
return self256->children[index];
|
||||
}
|
||||
default: // GCOVR_EXCL_LINE
|
||||
__builtin_unreachable(); // GCOVR_EXCL_LINE
|
||||
@@ -1250,7 +1249,7 @@ void maybeDownsize(Node *self, NodeAllocators *allocators,
|
||||
getInTree(self, impl) = newSelf;
|
||||
allocators->node3.release(self3);
|
||||
} else if (self->numChildren == 1 && !self->entryPresent) {
|
||||
auto *child = self3->children[0].child;
|
||||
auto *child = self3->children[0];
|
||||
int minCapacity = self3->partialKeyLen + 1 + child->partialKeyLen;
|
||||
|
||||
if (minCapacity > child->getCapacity()) {
|
||||
@@ -1363,7 +1362,7 @@ Node *erase(Node *self, NodeAllocators *allocators, ConflictSet::Impl *impl,
|
||||
sizeof(parent3->index[0]) *
|
||||
(parent->numChildren - (nodeIndex + 1)));
|
||||
memmove(parent3->children + nodeIndex, parent3->children + nodeIndex + 1,
|
||||
sizeof(parent3->children[0]) *
|
||||
sizeof(parent3->children[0]) * // NOLINT
|
||||
(parent->numChildren - (nodeIndex + 1)));
|
||||
memmove(parent3->childMaxVersion + nodeIndex,
|
||||
parent3->childMaxVersion + nodeIndex + 1,
|
||||
@@ -1381,7 +1380,7 @@ Node *erase(Node *self, NodeAllocators *allocators, ConflictSet::Impl *impl,
|
||||
sizeof(parent16->index[0]) *
|
||||
(parent->numChildren - (nodeIndex + 1)));
|
||||
memmove(parent16->children + nodeIndex, parent16->children + nodeIndex + 1,
|
||||
sizeof(parent16->children[0]) *
|
||||
sizeof(parent16->children[0]) * // NOLINT
|
||||
(parent->numChildren - (nodeIndex + 1)));
|
||||
memmove(parent16->childMaxVersion + nodeIndex,
|
||||
parent16->childMaxVersion + nodeIndex + 1,
|
||||
@@ -1411,7 +1410,7 @@ Node *erase(Node *self, NodeAllocators *allocators, ConflictSet::Impl *impl,
|
||||
Node48::kMaxOfMaxShift],
|
||||
parent48->childMaxVersion[toRemoveChildrenIndex]);
|
||||
auto parentIndex =
|
||||
parent48->children[toRemoveChildrenIndex].child->parentsIndex;
|
||||
parent48->children[toRemoveChildrenIndex]->parentsIndex;
|
||||
parent48->index[parentIndex] = toRemoveChildrenIndex;
|
||||
parent48->reverseIndex[toRemoveChildrenIndex] = parentIndex;
|
||||
}
|
||||
@@ -1425,7 +1424,7 @@ Node *erase(Node *self, NodeAllocators *allocators, ConflictSet::Impl *impl,
|
||||
case Type_Node256: {
|
||||
auto *parent256 = static_cast<Node256 *>(parent);
|
||||
parent256->bitSet.reset(parentsIndex);
|
||||
parent256->children[parentsIndex].child = nullptr;
|
||||
parent256->children[parentsIndex] = nullptr;
|
||||
|
||||
--parent->numChildren;
|
||||
|
||||
|
Reference in New Issue
Block a user