Skip to content

Commit 2b9cf5c

Browse files
ramananeeshJslYoon
andauthored
[Integration] Adding ART to the benchmark (#38)
* ART integration - work in progress * art fixes * fixing execute * fixed art * clean up code * merge from master * fixed minor bug --------- Co-authored-by: Lucas <[email protected]>
1 parent b87c2bf commit 2b9cf5c

File tree

10 files changed

+143
-16
lines changed

10 files changed

+143
-16
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,15 +189,19 @@ cython_debug/
189189
.cache
190190
build
191191

192-
# IDE
192+
# IDE - VSCode
193193
.vscode/
194194
script/infra/__pycache__
195195
results.db
196196
data/*.data
197197
*.bin
198198

199+
# IDE - IntelliJ
199200
.idea
200201
cmake-build-debug/
201202
src/bliss/.idea/
202203

204+
# OS - MacOS
203205
db_working_home
206+
207+

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ add_library(bliss OBJECT
5252
${CMAKE_SOURCE_DIR}/src/bliss/bench_alex.h
5353
${CMAKE_SOURCE_DIR}/src/bliss/bench_btree.h
5454
${CMAKE_SOURCE_DIR}/src/bliss/bench_pgm.h
55+
${CMAKE_SOURCE_DIR}/src/bliss/bench_art.h
5556
)
5657

5758
target_compile_features(bliss PUBLIC
@@ -65,6 +66,7 @@ target_link_libraries(bliss PUBLIC
6566
lipp
6667
tlx
6768
pgm
69+
art
6870
)
6971

7072
target_include_directories(bliss PUBLIC

external/CMakeLists.txt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,19 @@ endif()
7272
add_library(tlx INTERFACE)
7373
target_include_directories(tlx INTERFACE ${tlx_SOURCE_DIR}/)
7474

75+
# Adaptive Radix Tree
76+
FetchContent_Declare(
77+
art
78+
GIT_REPOSITORY https://github.com/BU-DiSC/ART
79+
GIT_TAG main
80+
)
81+
FetchContent_GetProperties(art)
82+
if (NOT art_POPULATED)
83+
FetchContent_Populate(art)
84+
endif()
85+
86+
add_library(art INTERFACE)
87+
target_include_directories(art INTERFACE ${art_SOURCE_DIR})
7588

7689

7790

@@ -86,4 +99,4 @@ if (NOT pgm_POPULATED)
8699
endif()
87100

88101
add_library(pgm INTERFACE)
89-
target_include_directories(pgm INTERFACE ${pgm_SOURCE_DIR})
102+
target_include_directories(pgm INTERFACE ${pgm_SOURCE_DIR})

src/bliss/bench_art.h

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#ifndef BLISS_BENCH_ART
2+
#define BLISS_BENCH_ART
3+
4+
#include <vector>
5+
6+
#include "ART.h"
7+
#include "bliss/bliss_index.h"
8+
#include "spdlog/spdlog.h"
9+
10+
namespace bliss {
11+
12+
template <typename KEY_TYPE, typename VALUE_TYPE>
13+
class BlissARTIndex : public BlissIndex<KEY_TYPE, VALUE_TYPE> {
14+
public:
15+
ART::ArtNode* _index;
16+
static constexpr size_t KEY_SIZE = sizeof(KEY_TYPE);
17+
BlissARTIndex() { _index = nullptr; };
18+
19+
void bulkload(
20+
std::vector<std::pair<KEY_TYPE, VALUE_TYPE>> values) override {
21+
// expects the pairs to be pre-sorted before performing bulk load
22+
for (const auto pair : values) {
23+
put(pair.first, pair.second);
24+
}
25+
}
26+
27+
bool get(KEY_TYPE key) override {
28+
uint8_t ARTkey[KEY_SIZE];
29+
ART::loadKey(key, ARTkey);
30+
ART::ArtNode* leaf =
31+
ART::lookup(_index, ARTkey, KEY_SIZE, 0, KEY_SIZE);
32+
return leaf != nullptr && ART::isLeaf(leaf);
33+
}
34+
35+
void put(KEY_TYPE key, VALUE_TYPE value) override {
36+
uint8_t ARTkey[KEY_SIZE];
37+
ART::loadKey(key, ARTkey);
38+
ART::insert(_index, &_index, ARTkey, 0, key, KEY_SIZE);
39+
}
40+
41+
void end_routine() override {}
42+
};
43+
44+
} // namespace bliss
45+
46+
#endif

src/bliss/bench_btree.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ class BlissBTreeIndex : public BlissIndex<KEY_TYPE, VALUE_TYPE> {
2020
this->_index.bulk_load(values.begin(), values.end());
2121
}
2222

23-
bool get(KEY_TYPE key) override { return this->_index.exists(key); }
23+
bool get(KEY_TYPE key) override {
24+
return this->_index.exists(key); }
2425

2526
void put(KEY_TYPE key, VALUE_TYPE value) override {
2627
this->_index.insert(std::make_pair(key, value));

src/bliss_bench.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include "bliss/bench_pgm.h"
1111
#include "bliss/bench_alex.h"
12+
#include "bliss/bench_art.h"
1213
#include "bliss/bench_btree.h"
1314
#include "bliss/bench_lipp.h"
1415
#include "bliss/bliss_index.h"
@@ -170,6 +171,8 @@ int main(int argc, char *argv[]) {
170171
index.reset(new bliss::BlissLippIndex<key_type, value_type>());
171172
} else if (config.index == "btree") {
172173
index.reset(new bliss::BlissBTreeIndex<key_type, value_type>());
174+
} else if (config.index == "art") {
175+
index.reset(new bliss::BlissARTIndex<key_type, value_type>());
173176
} else if (config.index == "pgm") {
174177
index.reset(new bliss::BlissPGMIndex<key_type, value_type>());
175178
} else {

tests/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ target_include_directories(bliss_test_infra PUBLIC
1616

1717
add_subdirectory(test_alex)
1818
add_subdirectory(test_lipp)
19-
add_subdirectory(test_btree)
19+
add_subdirectory(test_btree)
20+
add_subdirectory(test_art)

tests/bliss_index_tests.h

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
#ifndef BLISS_INDEX_TESTS_H
22
#define BLISS_INDEX_TESTS_H
3+
#include "include/pgm/pgm_index_dynamic.hpp"
34
#include <alex.h>
45
#include <gtest/gtest.h>
56
#include <lipp.h>
67
#include <spdlog/common.h>
7-
#include "include/pgm/pgm_index_dynamic.hpp"
88

9+
#include <algorithm>
910
#include <cxxopts.hpp>
1011
#include <iostream>
11-
#include <string>
12-
#include <algorithm>
1312
#include <random>
13+
#include <string>
1414

15-
#include "bliss/bench_pgm.h"
1615
#include "bliss/bench_alex.h"
16+
#include "bliss/bench_art.h"
1717
#include "bliss/bench_btree.h"
1818
#include "bliss/bench_lipp.h"
19+
#include "bliss/bench_pgm.h"
1920
#include "bliss/bliss_index.h"
2021
#include "bliss/util/args.h"
2122
#include "bliss/util/config.h"
@@ -28,20 +29,25 @@ using namespace bliss::utils;
2829
using key_type = unsigned long;
2930
using value_type = unsigned long;
3031

31-
class BlissIndexTest : public testing::Test {
32-
protected:
32+
class BlissIndexTest : public testing::Test
33+
{
34+
protected:
3335
std::unique_ptr<bliss::BlissIndex<key_type, value_type>> index;
34-
std::string indexes[4] = {"alex", "lipp", "btree", "pgm"};
36+
std::string indexes[5] = {"alex", "lipp", "btree", "pgm", "art"};
3537
int num_keys = 100000;
3638

37-
void SetUp() {}
39+
void SetUp()
40+
{
41+
}
3842

39-
void GenerateData(std::vector<key_type> &data, int num_keys,
40-
bool sorted = true) {
41-
for (int i = 0; i < num_keys; i++) {
43+
void GenerateData(std::vector<key_type> &data, int num_keys, bool sorted = true)
44+
{
45+
for (int i = 0; i < num_keys; i++)
46+
{
4247
data.push_back(i);
4348
}
44-
if (!sorted) {
49+
if (!sorted)
50+
{
4551
std::random_device rd;
4652
std::mt19937 g(rd());
4753
std::shuffle(data.begin(), data.end(), g);

tests/test_art/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
get_filename_component(EXEC ${CMAKE_CURRENT_SOURCE_DIR} NAME)
2+
file(GLOB_RECURSE CPP_TESTS "*_tests.cpp")
3+
add_executable(${EXEC} ${CPP_TESTS})
4+
target_link_libraries(${EXEC} PRIVATE
5+
bliss
6+
bliss_test_infra
7+
GTest::gtest_main)
8+
include(GoogleTest)
9+
gtest_discover_tests(${EXEC})

tests/test_art/art_tests.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#include "bliss_index_tests.h"
2+
3+
class ArtTest : public BlissIndexTest {};
4+
5+
6+
TEST_F(ArtTest, TestArt_Sanity) {
7+
index.reset(new bliss::BlissARTIndex<key_type, key_type>());
8+
std::vector<key_type> data;
9+
int key = 100'000;
10+
int value = 123'456;
11+
index->put(key, value);
12+
EXPECT_TRUE(index->get(key));
13+
}
14+
15+
16+
TEST_F(ArtTest, TestArt_Sorted) {
17+
index.reset(new bliss::BlissARTIndex<key_type, key_type>());
18+
std::vector<key_type> data;
19+
GenerateData(data, num_keys);
20+
21+
auto insert_start = data.begin();
22+
auto insert_end = data.end();
23+
executor::execute_inserts(*index, insert_start, insert_end);
24+
25+
for (auto key : data) {
26+
EXPECT_TRUE(index->get(key));
27+
}
28+
}
29+
30+
TEST_F(ArtTest, TestArt_Random) {
31+
index.reset(new bliss::BlissARTIndex<key_type, key_type>());
32+
std::vector<key_type> data;
33+
GenerateData(data, num_keys, false);
34+
35+
auto insert_start = data.begin();
36+
auto insert_end = data.end();
37+
executor::execute_inserts(*index, insert_start, insert_end);
38+
39+
for (auto key : data) {
40+
EXPECT_TRUE(index->get(key));
41+
}
42+
}

0 commit comments

Comments
 (0)