Skip to content

Commit

Permalink
ART integration - work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
ramananeesh committed Oct 2, 2024
1 parent ace484d commit 9200084
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 3 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,19 @@ cython_debug/
.cache
build

# IDE
# IDE - VSCode
.vscode/
script/infra/__pycache__
results.db
data/*.data
*.bin

# IDE - IntelliJ
.idea
cmake-build-debug/
src/bliss/.idea/

# OS - MacOS
db_working_home


2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ add_library(bliss OBJECT
${CMAKE_SOURCE_DIR}/src/bliss/bench_lipp.h
${CMAKE_SOURCE_DIR}/src/bliss/bench_alex.h
${CMAKE_SOURCE_DIR}/src/bliss/bench_btree.h
${CMAKE_SOURCE_DIR}/src/bliss/bench_art.h
)

target_compile_features(bliss PUBLIC
Expand All @@ -63,6 +64,7 @@ target_link_libraries(bliss PUBLIC
alex
lipp
tlx
art
)

target_include_directories(bliss PUBLIC
Expand Down
16 changes: 15 additions & 1 deletion external/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,18 @@ if (NOT tlx_POPULATED)
endif()

add_library(tlx INTERFACE)
target_include_directories(tlx INTERFACE ${tlx_SOURCE_DIR}/)
target_include_directories(tlx INTERFACE ${tlx_SOURCE_DIR}/)

# Adaptive Radix Tree
FetchContent_Declare(
art
GIT_REPOSITORY https://github.com/BU-DiSC/ART
GIT_TAG main
)
FetchContent_GetProperties(art)
if (NOT art_POPULATED)
FetchContent_Populate(art)
endif()

add_library(art INTERFACE)
target_include_directories(art INTERFACE ${art_SOURCE_DIR})
51 changes: 51 additions & 0 deletions src/bliss/bench_art.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#ifndef BLISS_BENCH_ART
#define BLISS_BENCH_ART

#include <vector>

#include "ART.h"
#include "bliss/bliss_index.h"
#include "spdlog/spdlog.h"

namespace bliss {

template <typename KEY_TYPE, typename VALUE_TYPE>
class BlissARTIndex : public BlissIndex<KEY_TYPE, VALUE_TYPE> {
public:
static constexpr size_t KEY_SIZE = sizeof(KEY_TYPE);
ART::ArtNode* _index;
BlissARTIndex() { _index = nullptr; };

void bulkload(
std::vector<std::pair<KEY_TYPE, VALUE_TYPE>> values) override {
// expects the pairs to be pre-sorted before performing bulk load
for (const auto& pair : values) {
put(pair.first, pair.second);
}
}

bool get(KEY_TYPE key) override {
uint8_t ARTkey[KEY_SIZE];
ART::loadKey(key, ARTkey);
uint8_t depth = 0;
ART::ArtNode* leaf =
ART::lookup(_index, ARTkey, KEY_SIZE, depth, KEY_SIZE);
return ART::isLeaf(leaf) && ART::getLeafValue(leaf) == key;
}

void put(KEY_TYPE key, VALUE_TYPE value) override {
uint8_t ARTkey[KEY_SIZE];
ART::loadKey(key, ARTkey);

// function signature for insert:
// void insert(ArtNode* ArtNode, ArtNode** nodeRef, uint8_t key[],
// unsigned depth, uintptr_t value, unsigned maxKeyLength)
ART::insert(_index, &_index, ARTkey, 0, value, KEY_SIZE);
}

void end_routine() override {}
};

} // namespace bliss

#endif
3 changes: 3 additions & 0 deletions src/bliss_bench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <string>

#include "bliss/bench_alex.h"
#include "bliss/bench_art.h"
#include "bliss/bench_btree.h"
#include "bliss/bench_lipp.h"
#include "bliss/bliss_index.h"
Expand Down Expand Up @@ -168,6 +169,8 @@ int main(int argc, char *argv[]) {
index.reset(new bliss::BlissLippIndex<key_type, value_type>());
} else if (config.index == "btree") {
index.reset(new bliss::BlissBTreeIndex<key_type, value_type>());
} else if (config.index == "art") {
index.reset(new bliss::BlissARTIndex<key_type, value_type>());
} else {
spdlog::error(config.index + " not implemented yet", 1);
}
Expand Down
3 changes: 2 additions & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ target_include_directories(bliss_test_infra PUBLIC

add_subdirectory(test_alex)
add_subdirectory(test_lipp)
add_subdirectory(test_btree)
add_subdirectory(test_btree)
add_subdirectory(test_art)
1 change: 1 addition & 0 deletions tests/bliss_index_tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <string>

#include "bliss/bench_alex.h"
#include "bliss/bench_art.h"
#include "bliss/bench_btree.h"
#include "bliss/bench_lipp.h"
#include "bliss/bliss_index.h"
Expand Down
9 changes: 9 additions & 0 deletions tests/test_art/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
get_filename_component(EXEC ${CMAKE_CURRENT_SOURCE_DIR} NAME)
file(GLOB_RECURSE CPP_TESTS "*_tests.cpp")
add_executable(${EXEC} ${CPP_TESTS})
target_link_libraries(${EXEC} PRIVATE
bliss
bliss_test_infra
GTest::gtest_main)
include(GoogleTest)
gtest_discover_tests(${EXEC})
31 changes: 31 additions & 0 deletions tests/test_art/art_tests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include "bliss_index_tests.h"

class ArtTest : public BlissIndexTest {};

TEST_F(ArtTest, TestArt_Sorted) {
index.reset(new bliss::BlissARTIndex<key_type, key_type>());
std::vector<key_type> data;
GenerateData(data, num_keys);

auto insert_start = data.begin();
auto insert_end = data.end();
executor::execute_inserts(*index, insert_start, insert_end);

for (auto key : data) {
EXPECT_TRUE(index->get(key));
}
}

TEST_F(ArtTest, TestArt_Random) {
index.reset(new bliss::BlissARTIndex<key_type, key_type>());
std::vector<key_type> data;
GenerateData(data, num_keys, false);

auto insert_start = data.begin();
auto insert_end = data.end();
executor::execute_inserts(*index, insert_start, insert_end);

for (auto key : data) {
EXPECT_TRUE(index->get(key));
}
}

0 comments on commit 9200084

Please sign in to comment.