From 3a34d3cecb38cbd645d2805599964d41a011c764 Mon Sep 17 00:00:00 2001 From: Andrew Noyes Date: Fri, 15 Nov 2024 16:29:17 -0800 Subject: [PATCH] Minor style improvements --- ConflictSet.cpp | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/ConflictSet.cpp b/ConflictSet.cpp index 98d9987..e7c1295 100644 --- a/ConflictSet.cpp +++ b/ConflictSet.cpp @@ -960,8 +960,7 @@ private: NodeAllocator node256; }; -int getNodeIndex(Node3 *self, uint8_t index) { - Node3 *n = (Node3 *)self; +int getNodeIndex(Node3 *n, uint8_t index) { assume(n->numChildren >= 1); assume(n->numChildren <= 3); for (int i = 0; i < n->numChildren; ++i) { @@ -972,8 +971,7 @@ int getNodeIndex(Node3 *self, uint8_t index) { return -1; } -int getNodeIndexExists(Node3 *self, uint8_t index) { - Node3 *n = (Node3 *)self; +int getNodeIndexExists(Node3 *n, uint8_t index) { assume(n->numChildren >= 1); assume(n->numChildren <= 3); for (int i = 0; i < n->numChildren; ++i) { @@ -1274,33 +1272,32 @@ TaggedNodePointer getChild(Node *self, uint8_t index) { struct ChildAndMaxVersion { TaggedNodePointer child; InternalVersionT maxVersion; + static ChildAndMaxVersion empty() { + ChildAndMaxVersion result; + result.child = nullptr; + return result; + } }; ChildAndMaxVersion getChildAndMaxVersion(Node0 *, uint8_t) { return {}; } ChildAndMaxVersion getChildAndMaxVersion(Node3 *self, uint8_t index) { int i = getNodeIndex(self, index); if (i < 0) { - ChildAndMaxVersion result; - result.child = nullptr; - return result; + return ChildAndMaxVersion::empty(); } return {self->children[i], self->childMaxVersion[i]}; } ChildAndMaxVersion getChildAndMaxVersion(Node16 *self, uint8_t index) { int i = getNodeIndex(self, index); if (i < 0) { - ChildAndMaxVersion result; - result.child = nullptr; - return result; + return ChildAndMaxVersion::empty(); } return {self->children[i], self->childMaxVersion[i]}; } ChildAndMaxVersion getChildAndMaxVersion(Node48 *self, uint8_t index) { int i = self->index[index]; if (i < 0) { - ChildAndMaxVersion result; - result.child = nullptr; - return result; + return ChildAndMaxVersion::empty(); } return {self->children[i], self->childMaxVersion[i]}; } @@ -1383,17 +1380,11 @@ TaggedNodePointer getChildGeq(Node16 *self, int child) { TaggedNodePointer getChildGeq(Node48 *self, int child) { int c = self->bitSet.firstSetGeq(child); - if (c < 0) { - return nullptr; - } - return self->children[self->index[c]]; + return c < 0 ? nullptr : self->children[self->index[c]]; } TaggedNodePointer getChildGeq(Node256 *self, int child) { int c = self->bitSet.firstSetGeq(child); - if (c < 0) { - return nullptr; - } - return self->children[c]; + return c < 0 ? nullptr : self->children[c]; } TaggedNodePointer getChildGeq(Node *self, int child) {