Add specializations for partialKey()

This commit is contained in:
2024-03-08 14:01:56 -08:00
parent 93e487c8fb
commit 0c8cb8faa5
2 changed files with 10 additions and 13 deletions

View File

@@ -15,12 +15,4 @@ repos:
description: disallow checking in DEBUG_VERBOSE=1
entry: '^#define DEBUG_VERBOSE 1$'
language: pygrep
types: [c++]
- repo: local
hooks:
- id: debug verbose check
name: disallow checking in SHOW_MEMORY=1
description: disallow checking in SHOW_MEMORY=1
entry: '^#define SHOW_MEMORY 1$'
language: pygrep
types: [c++]

View File

@@ -200,6 +200,7 @@ struct Node0 : Node {
uint8_t index[16]; // 16 so that we can use the same simd index search
// implementation as Node16
Node0() { this->type = Type::Node0; }
uint8_t *partialKey() { return (uint8_t *)(this + 1); }
};
struct Node4 : Node {
@@ -208,6 +209,7 @@ struct Node4 : Node {
// implementation as Node16
Child children[4];
Node4() { this->type = Type::Node4; }
uint8_t *partialKey() { return (uint8_t *)(this + 1); }
};
struct Node16 : Node {
@@ -215,6 +217,7 @@ struct Node16 : Node {
uint8_t index[16];
Child children[16];
Node16() { this->type = Type::Node16; }
uint8_t *partialKey() { return (uint8_t *)(this + 1); }
};
struct Node48 : Node {
@@ -226,6 +229,7 @@ struct Node48 : Node {
memset(index, -1, 256);
this->type = Type::Node48;
}
uint8_t *partialKey() { return (uint8_t *)(this + 1); }
};
struct Node256 : Node {
@@ -237,6 +241,7 @@ struct Node256 : Node {
children[i].child = nullptr;
}
}
uint8_t *partialKey() { return (uint8_t *)(this + 1); }
};
template <class NodeT> NodeT *newNode(int partialKeyCapacity) {
@@ -250,15 +255,15 @@ template <class NodeT> NodeT *newNode(int partialKeyCapacity) {
uint8_t *Node::partialKey() {
switch (type) {
case Type::Node0:
return (uint8_t *)((Node0 *)this + 1);
return ((Node0 *)this)->partialKey();
case Type::Node4:
return (uint8_t *)((Node4 *)this + 1);
return ((Node4 *)this)->partialKey();
case Type::Node16:
return (uint8_t *)((Node16 *)this + 1);
return ((Node16 *)this)->partialKey();
case Type::Node48:
return (uint8_t *)((Node48 *)this + 1);
return ((Node48 *)this)->partialKey();
case Type::Node256:
return (uint8_t *)((Node256 *)this + 1);
return ((Node256 *)this)->partialKey();
}
}