1 | #include "duckdb/execution/index/art/node.hpp" |
2 | #include "duckdb/execution/index/art/art.hpp" |
3 | #include "duckdb/common/exception.hpp" |
4 | |
5 | using namespace duckdb; |
6 | |
7 | Node::Node(ART &art, NodeType type, size_t compressedPrefixSize) : prefix_length(0), count(0), type(type) { |
8 | this->prefix = unique_ptr<uint8_t[]>(new uint8_t[compressedPrefixSize]); |
9 | } |
10 | |
11 | void Node::CopyPrefix(ART &art, Node *src, Node *dst) { |
12 | dst->prefix_length = src->prefix_length; |
13 | memcpy(dst->prefix.get(), src->prefix.get(), src->prefix_length); |
14 | } |
15 | |
16 | unique_ptr<Node> *Node::GetChild(idx_t pos) { |
17 | assert(0); |
18 | return nullptr; |
19 | } |
20 | |
21 | idx_t Node::GetMin() { |
22 | assert(0); |
23 | return 0; |
24 | } |
25 | |
26 | uint32_t Node::PrefixMismatch(ART &art, Node *node, Key &key, uint64_t depth) { |
27 | uint64_t pos; |
28 | for (pos = 0; pos < node->prefix_length; pos++) { |
29 | if (key[depth + pos] != node->prefix[pos]) { |
30 | return pos; |
31 | } |
32 | } |
33 | return pos; |
34 | } |
35 | |
36 | void Node::InsertLeaf(ART &art, unique_ptr<Node> &node, uint8_t key, unique_ptr<Node> &newNode) { |
37 | switch (node->type) { |
38 | case NodeType::N4: |
39 | Node4::insert(art, node, key, newNode); |
40 | break; |
41 | case NodeType::N16: |
42 | Node16::insert(art, node, key, newNode); |
43 | break; |
44 | case NodeType::N48: |
45 | Node48::insert(art, node, key, newNode); |
46 | break; |
47 | case NodeType::N256: |
48 | Node256::insert(art, node, key, newNode); |
49 | break; |
50 | default: |
51 | assert(0); |
52 | } |
53 | } |
54 | |
55 | void Node::Erase(ART &art, unique_ptr<Node> &node, idx_t pos) { |
56 | switch (node->type) { |
57 | case NodeType::N4: { |
58 | Node4::erase(art, node, pos); |
59 | break; |
60 | } |
61 | case NodeType::N16: { |
62 | Node16::erase(art, node, pos); |
63 | break; |
64 | } |
65 | case NodeType::N48: { |
66 | Node48::erase(art, node, pos); |
67 | break; |
68 | } |
69 | case NodeType::N256: |
70 | Node256::erase(art, node, pos); |
71 | break; |
72 | default: |
73 | assert(0); |
74 | break; |
75 | } |
76 | } |
77 | |