From ddca6e85118298734754bb5797d2616e33031385 Mon Sep 17 00:00:00 2001 From: Andrew Noyes Date: Fri, 9 Feb 2024 18:14:07 -0800 Subject: [PATCH] Rely on bitSet for child existence in Node48 --- ConflictSet.cpp | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/ConflictSet.cpp b/ConflictSet.cpp index aae7186..4994e6b 100644 --- a/ConflictSet.cpp +++ b/ConflictSet.cpp @@ -152,10 +152,7 @@ struct Node48 : Node { Node *children[48] = {}; int8_t nextFree = 0; int8_t index[256]; - Node48() { - this->type = Type::Node48; - memset(index, -1, 256); - } + Node48() { this->type = Type::Node48; } }; struct Node256 : Node { @@ -241,10 +238,8 @@ Node *&getChildExists(Node *self, uint8_t index) { return self16->children[getNodeIndex(self16, index)]; } else if (self->type == Type::Node48) { auto *self48 = static_cast(self); - int secondIndex = self48->index[index]; - if (secondIndex >= 0) { - return self48->children[secondIndex]; - } + assert(self48->bitSet.test(index)); + return self48->children[self48->index[index]]; } else { auto *self256 = static_cast(self); return self256->children[index]; @@ -416,15 +411,14 @@ Node *&getOrCreateChild(Node *&self, uint8_t index) { } else if (self->type == Type::Node48) { insert48: auto *self48 = static_cast(self); - int secondIndex = self48->index[index]; - if (secondIndex >= 0) { - return self48->children[secondIndex]; + if (self48->bitSet.test(index)) { + return self48->children[self48->index[index]]; } if (self->numChildren == 48) { auto *newSelf = new (safe_malloc(sizeof(Node256))) Node256; memcpy((void *)newSelf, self, offsetof(Node, type)); for (int i = 0; i < 256; ++i) { - if (self48->index[i] >= 0) { + if (self48->bitSet.test(i)) { newSelf->bitSet.set(i); newSelf->children[i] = self48->children[self48->index[i]]; } @@ -475,7 +469,7 @@ void eraseChild(Node *self, uint8_t index) { } else if (self->type == Type::Node48) { auto *self48 = static_cast(self); self48->bitSet.reset(index); - int8_t toRemoveChildrenIndex = std::exchange(self48->index[index], -1); + int8_t toRemoveChildrenIndex = self48->index[index]; int8_t lastChildrenIndex = --self48->nextFree; assert(toRemoveChildrenIndex >= 0); assert(lastChildrenIndex >= 0);