1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
use crateArtNode;
use crateArtKey;
/// Art is an **adaptive radix tree**, which are also known as radix trees and
/// prefix trees.
///
/// Art requires 3 generic parameters, where `K` needs to implement the [ArtKey] trait and `V` is
/// self-explanatory. `MAX_PARTIAL_LEN` specifies the size of the array used by each inner node to
/// store the common prefix.
///
/// **Note:** `MAX_PARTIAL_LEN` is designed as a constant generic parameter because setting its size
/// requires users trade-off.
///
/// Radix tress consist of two types of nodes: inner and leaf nodes. Inner node map
/// partial keys to other nodes and leaf node store key-value pair.
///
/// For large keys, comparisons actually take $O(k)$ time. the complexity of
/// search trees is $O(k\log_n)$ and the art complexity of $O(k)$.
///
/// Art key idea that achieves both space and time efficiency is to adaptively use different node size with
/// the same, relatively large space, but with different fan-out.
///
/// Specifically, Art uses four node types of dynamically adaptive representation of inner nodes to
/// achieve space and time efficiency.
/// 1. Node4, which store up to 4 child pointers and uses an array of length 4 for keys. The keys
/// and pointers are stored at corresponding positions and the keys are sorted. In the
/// future,Art will no maintenance order and use simd.
/// 2. Node16, Which storing 5 and 16 child pointers. Like the Node4, the keys and pointers
/// are stored in separate arrays at corresponding positions, but both arrays have space
/// for 16 entries. **A key use SIMD instructions to parallel comparisons on modern hardware.**
/// 3. Node48, which node storing 17 and 48 child pointers. Unlike Node4 and Node16, Node48 uses
/// an array of length 256 for keys to index child. because seaching becomes expensive.
/// 4. Node256, which largest node type is simply an array of 256 pointers.
///
///
/// See [The Adaptive Radix Tree: ARTful indexing for Main-Memory Databases](https://db.in.tum.de/~leis/papers/ART.pdf)
/// for more information.