Add overloads of getChild for each type

This commit is contained in:
2024-08-01 11:42:55 -07:00
parent 4b3df0a426
commit 3b2bd16cd1

View File

@@ -891,29 +891,33 @@ void setMaxVersion(Node *n, ConflictSet::Impl *, InternalVersionT maxVersion);
Node *&getInTree(Node *n, ConflictSet::Impl *);
Node *getChild(Node0 *, uint8_t) { return nullptr; }
Node *getChild(Node3 *self, uint8_t index) {
int i = getNodeIndex(self, index);
return i < 0 ? nullptr : self->children[i];
}
Node *getChild(Node16 *self, uint8_t index) {
int i = getNodeIndex(self, index);
return i < 0 ? nullptr : self->children[i];
}
Node *getChild(Node48 *self, uint8_t index) {
int i = self->index[index];
return i < 0 ? nullptr : self->children[i];
}
Node *getChild(Node256 *self, uint8_t index) { return self->children[index]; }
Node *getChild(Node *self, uint8_t index) {
switch (self->getType()) {
case Type_Node0:
return nullptr;
case Type_Node3: {
auto *self3 = static_cast<Node3 *>(self);
int i = getNodeIndex(self3, index);
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];
}
case Type_Node48: {
auto *self48 = static_cast<Node48 *>(self);
int i = self48->index[index];
return i < 0 ? nullptr : self48->children[i];
}
case Type_Node256: {
auto *self256 = static_cast<Node256 *>(self);
return self256->children[index];
}
return getChild(static_cast<Node0 *>(self), index);
case Type_Node3:
return getChild(static_cast<Node3 *>(self), index);
case Type_Node16:
return getChild(static_cast<Node16 *>(self), index);
case Type_Node48:
return getChild(static_cast<Node48 *>(self), index);
case Type_Node256:
return getChild(static_cast<Node256 *>(self), index);
default: // GCOVR_EXCL_LINE
__builtin_unreachable(); // GCOVR_EXCL_LINE
}