Move Node::type to beginning of Node

This prepares us to have a variable size leaf type
This commit is contained in:
andrew committed 2024-03-07 14:17:14 -08:00
1 parent 5e1fb1dac5
commit f2cd05c29d
1 file changed
+15 -9
+15 -9
View File
@@ -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<Node16 *>(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<Node48 *>(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 <bool kBegin>
*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;