diff --git a/ConflictSet.cpp b/ConflictSet.cpp index ff2a87b..7d26576 100644 --- a/ConflictSet.cpp +++ b/ConflictSet.cpp @@ -231,18 +231,18 @@ enum class Type : int8_t { constexpr static int kPartialKeyMaxLenEntryPresent = 24; struct Node { + Type type = Type::Invalid; + /* begin section that's copied to the next node */ + bool entryPresent = false; + uint8_t parentsIndex = 0; + int8_t partialKeyLen = 0; + int32_t numChildren = 0; Node *parent = nullptr; uint8_t partialKey[kPartialKeyMaxLenEntryPresent]; // If not entryPresent, then the partial key might spill over into entry Entry entry; - int32_t numChildren = 0; - bool entryPresent = false; - uint8_t parentsIndex = 0; - int8_t partialKeyLen = 0; /* end section that's copied to the next node */ - - Type type = Type::Invalid; }; static_assert(offsetof(Node, entry) == @@ -571,7 +571,9 @@ Node *&getOrCreateChild(Node *&self, uint8_t index, if (self->numChildren == 16) { auto *self16 = static_cast(self); auto *newSelf = allocators->node48.allocate(); - memcpy((void *)newSelf, self, offsetof(Node, type)); + memcpy((char *)newSelf + sizeof(Node::type), + (char *)self + sizeof(Node::type), + sizeof(Node) - sizeof(Node::type)); newSelf->nextFree = 16; int i = 0; for (auto x : self16->index) { @@ -610,7 +612,9 @@ Node *&getOrCreateChild(Node *&self, uint8_t index, if (self->numChildren == 48) { auto *self48 = static_cast(self); auto *newSelf = allocators->node256.allocate(); - memcpy((void *)newSelf, self, offsetof(Node, type)); + memcpy((char *)newSelf + sizeof(Node::type), + (char *)self + sizeof(Node::type), + sizeof(Node) - sizeof(Node::type)); newSelf->bitSet = self48->bitSet; newSelf->bitSet.forEachInRange( [&](int i) { @@ -1542,7 +1546,9 @@ template *self = allocators->node1.allocate(); - memcpy((void *)*self, old, offsetof(Node, type)); + memcpy((char *)*self + sizeof(Node::type), + (char *)old + sizeof(Node::type), + sizeof(Node) - sizeof(Node::type)); (*self)->partialKeyLen = partialKeyIndex; (*self)->entryPresent = false; (*self)->numChildren = 0;