Skip to content

Commit 729e743

Browse files
author
Can Gokmen
committed
Fixed prefix issue that would cause problems with big ints
1 parent 3021bf3 commit 729e743

6 files changed

Lines changed: 22 additions & 21 deletions

File tree

‎ArtNode.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ static const int8_t NodeType256 = 3;
3838
// The maximum prefix length for compressed paths stored in the
3939
// header, if the path is longer it is loaded from the database on
4040
// demand
41-
static const unsigned maxPrefixLength = 4;
41+
static const unsigned maxPrefixLength = 5;
4242

4343
// Shared header of all inner nodes
4444
struct ArtNode {

‎Helper.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ void loadKey(uint32_t tid, uint8_t key[]) {
3636
// Store the key of the tuple into the key vector
3737
// Implementation is database specific
3838
reinterpret_cast<uint32_t*>(key)[0] = __builtin_bswap32(tid);
39+
key[4] = 0; // null terminator byte
3940
}
4041

4142
static inline unsigned ctz(uint16_t x) {

‎run.cpp‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ int main(int argc, char** argv) {
111111
long long query_time = 0;
112112
for (uint64_t i = 0; i < (uint64_t)N / 100; i++) {
113113
int random = rand() % N + 1;
114-
uint8_t key[4];
114+
uint8_t key[5];
115115
ART::loadKey(keys_to_load[random], key);
116116
auto start = chrono::high_resolution_clock::now();
117117
ART::ArtNode* leaf = tree->lookup(key);
@@ -132,7 +132,7 @@ int main(int argc, char** argv) {
132132
} else {
133133
// Regular ART insertion
134134
for (uint64_t i = 0; i < N; i++) {
135-
uint8_t key[4];
135+
uint8_t key[5];
136136
ART::loadKey(keys[i], key);
137137
auto start = chrono::high_resolution_clock::now();
138138
tree->insert(key, keys[i]);
@@ -146,7 +146,7 @@ int main(int argc, char** argv) {
146146
long long query_time = 0;
147147
for (uint64_t i = 0; i < (uint64_t)N / 100; i++) {
148148
int random = rand() % (maxval - minval + 1) + minval;
149-
uint8_t key[4];
149+
uint8_t key[5];
150150
ART::loadKey(keys[random], key);
151151
auto start = chrono::high_resolution_clock::now();
152152
ART::ArtNode* leaf = tree->lookup(key);
@@ -168,7 +168,7 @@ int main(int argc, char** argv) {
168168
ART::QuART_tail* tree = new ART::QuART_tail();
169169
long long insertion_time = 0;
170170
for (uint64_t i = 0; i < N; i++) {
171-
uint8_t key[4];
171+
uint8_t key[5];
172172
ART::loadKey(keys[i], key);
173173
auto start = chrono::high_resolution_clock::now();
174174
tree->insert(key, keys[i]);
@@ -190,7 +190,7 @@ int main(int argc, char** argv) {
190190
long long query_time = 0;
191191
for (uint64_t i = 0; i < (uint64_t)N / 100; i++) {
192192
int random = rand() % (maxval - minval + 1) + minval;
193-
uint8_t key[4];
193+
uint8_t key[5];
194194
ART::loadKey(keys[random], key);
195195
auto start = chrono::high_resolution_clock::now();
196196
ART::ArtNode* leaf = tree->lookup(key);
@@ -214,7 +214,7 @@ int main(int argc, char** argv) {
214214
ART::QuART_lil* tree = new ART::QuART_lil();
215215
long long insertion_time = 0;
216216
for (uint64_t i = 0; i < N; i++) {
217-
uint8_t key[4];
217+
uint8_t key[5];
218218
ART::loadKey(keys[i], key);
219219
auto start = chrono::high_resolution_clock::now();
220220
tree->insert(key, keys[i]);
@@ -234,7 +234,7 @@ int main(int argc, char** argv) {
234234
long long query_time = 0;
235235
for (uint64_t i = 0; i < (uint64_t)N / 100; i++) {
236236
int random = rand() % (maxval - minval + 1) + minval;
237-
uint8_t key[4];
237+
uint8_t key[5];
238238
ART::loadKey(keys[random], key);
239239
auto start = chrono::high_resolution_clock::now();
240240
ART::ArtNode* leaf = tree->lookup(key);
@@ -256,7 +256,7 @@ int main(int argc, char** argv) {
256256
ART::QuART_stail* tree = new ART::QuART_stail();
257257
long long insertion_time = 0;
258258
for (uint64_t i = 0; i < N; i++) {
259-
uint8_t key[4];
259+
uint8_t key[5];
260260
ART::loadKey(keys[i], key);
261261
auto start = chrono::high_resolution_clock::now();
262262
tree->insert(key, keys[i]);
@@ -276,7 +276,7 @@ int main(int argc, char** argv) {
276276
long long query_time = 0;
277277
for (uint64_t i = 0; i < (uint64_t)N / 100; i++) {
278278
int random = rand() % (maxval - minval + 1) + minval;
279-
uint8_t key[4];
279+
uint8_t key[5];
280280
ART::loadKey(keys[random], key);
281281
auto start = chrono::high_resolution_clock::now();
282282
ART::ArtNode* leaf = tree->lookup(key);
@@ -298,7 +298,7 @@ int main(int argc, char** argv) {
298298
ART::QuART_lil* tree = new ART::QuART_lil();
299299
long long insertion_time = 0;
300300
for (uint64_t i = 0; i < N; i++) {
301-
uint8_t key[4];
301+
uint8_t key[5];
302302
ART::loadKey(keys[i], key);
303303
auto start = chrono::high_resolution_clock::now();
304304
tree->insert(key, keys[i]);
@@ -318,7 +318,7 @@ int main(int argc, char** argv) {
318318
long long query_time = 0;
319319
for (uint64_t i = 0; i < (uint64_t)N / 100; i++) {
320320
int random = rand() % (maxval - minval + 1) + minval;
321-
uint8_t key[4];
321+
uint8_t key[5];
322322
ART::loadKey(keys[random], key);
323323
auto start = chrono::high_resolution_clock::now();
324324
ART::ArtNode* leaf = tree->lookup(key);

‎trees/QuART_lil.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ class QuART_lil : public QuART {
2828
int leafValue = getLeafValue(this->fp_leaf);
2929

3030
// Check whether all bytes except the last match fp_leaf.
31-
for (size_t i = 0; i < maxPrefixLength - 1; ++i) {
31+
for (size_t i = 0; i < maxPrefixLength - 2; ++i) {
3232
uint8_t leafByte =
33-
(leafValue >> (8 * (maxPrefixLength - 1 - i))) & 0xFF;
33+
(leafValue >> (8 * (maxPrefixLength - 2 - i))) & 0xFF;
3434
if (leafByte != key[i]) {
3535
// Upper bytes differ: restart from root.
3636
insert_recursive_change_fp(
@@ -40,7 +40,7 @@ class QuART_lil : public QuART {
4040
}
4141

4242
// Upper bytes match: fast path starting from fp.
43-
if (this->fp_depth == maxPrefixLength - 1) {
43+
if (this->fp_depth == maxPrefixLength - 2) {
4444
// fp is at the last-byte level; insert directly into the fp node.
4545
ArtNode* newNode = makeLeaf(value);
4646
switch (this->fp->type) {

‎trees/QuART_stail.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class QuART_stail : public QuART {
3333
if (type == KeyType::FP_INSERT) {
3434
if (this->reset_counter != RESET_COUNTER_INIT)
3535
this->reset_counter = RESET_COUNTER_INIT;
36-
if (this->fp_depth == maxPrefixLength - 1) {
36+
if (this->fp_depth == maxPrefixLength - 2) {
3737
// Insert leaf into fp
3838
ArtNode* newNode = makeLeaf(value);
3939
switch (this->fp->type) {

‎trees/QuART_tail.h‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ class QuART_tail : public QuART {
2323
int leafValue = getLeafValue(this->fp_leaf);
2424

2525
// Compare new key with current maximum (fp_leaf) byte by byte.
26-
for (size_t i = 0; i < maxPrefixLength - 1; i++) {
26+
for (size_t i = 0; i < maxPrefixLength - 2; i++) {
2727
uint8_t leafByte =
28-
(leafValue >> (8 * (maxPrefixLength - 1 - i))) & 0xFF;
28+
(leafValue >> (8 * (maxPrefixLength - 2 - i))) & 0xFF;
2929
if (key[i] > leafByte) {
3030
// New key is greater: it becomes the new maximum.
3131
insert_recursive_change_fp(
@@ -38,9 +38,9 @@ class QuART_tail : public QuART {
3838
return;
3939
}
4040
}
41-
if (key[3] > (leafValue & 0xFF)) {
41+
if (key[maxPrefixLength - 2] > (leafValue & 0xFF)) {
4242
// Upper bytes match: fast path starting from fp.
43-
if (this->fp_depth == maxPrefixLength - 1) {
43+
if (this->fp_depth == maxPrefixLength - 2) {
4444
// fp is at the last-byte level; insert directly into the fp node.
4545
ArtNode* newNode = makeLeaf(value);
4646
switch (this->fp->type) {
@@ -70,7 +70,7 @@ class QuART_tail : public QuART {
7070
}
7171
else {
7272
// Upper bytes match: fast path starting from fp.
73-
if (this->fp_depth == maxPrefixLength - 1) {
73+
if (this->fp_depth == maxPrefixLength - 2) {
7474
// fp is at the last-byte level; insert directly into the fp node.
7575
ArtNode* newNode = makeLeaf(value);
7676
switch (this->fp->type) {

0 commit comments

Comments
 (0)