Skip to content

Commit

Permalink
[Integration] Adding ART to the benchmark (#38)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
ramananeesh and JslYoon authored Jan 22, 2025
1 parent b87c2bf commit 2b9cf5c
Show file tree
Hide file tree
Showing 10 changed files with 143 additions and 16 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 @@ -52,6 +52,7 @@ add_library(bliss OBJECT
${CMAKE_SOURCE_DIR}/src/bliss/bench_alex.h
${CMAKE_SOURCE_DIR}/src/bliss/bench_btree.h
${CMAKE_SOURCE_DIR}/src/bliss/bench_pgm.h
${CMAKE_SOURCE_DIR}/src/bliss/bench_art.h
)

target_compile_features(bliss PUBLIC
Expand All @@ -65,6 +66,7 @@ target_link_libraries(bliss PUBLIC
lipp
tlx
pgm
art
)

target_include_directories(bliss PUBLIC
Expand Down
15 changes: 14 additions & 1 deletion external/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,19 @@ endif()
add_library(tlx INTERFACE)
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})



Expand All @@ -86,4 +99,4 @@ if (NOT pgm_POPULATED)
endif()

add_library(pgm INTERFACE)
target_include_directories(pgm INTERFACE ${pgm_SOURCE_DIR})
target_include_directories(pgm INTERFACE ${pgm_SOURCE_DIR})
46 changes: 46 additions & 0 deletions src/bliss/bench_art.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#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:
ART::ArtNode* _index;
static constexpr size_t KEY_SIZE = sizeof(KEY_TYPE);
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);
ART::ArtNode* leaf =
ART::lookup(_index, ARTkey, KEY_SIZE, 0, KEY_SIZE);
return leaf != nullptr && ART::isLeaf(leaf);
}

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

void end_routine() override {}
};

} // namespace bliss

#endif
3 changes: 2 additions & 1 deletion src/bliss/bench_btree.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ class BlissBTreeIndex : public BlissIndex<KEY_TYPE, VALUE_TYPE> {
this->_index.bulk_load(values.begin(), values.end());
}

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

void put(KEY_TYPE key, VALUE_TYPE value) override {
this->_index.insert(std::make_pair(key, value));
Expand Down
3 changes: 3 additions & 0 deletions src/bliss_bench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "bliss/bench_pgm.h"
#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 @@ -170,6 +171,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 if (config.index == "pgm") {
index.reset(new bliss::BlissPGMIndex<key_type, value_type>());
} else {
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)
30 changes: 18 additions & 12 deletions tests/bliss_index_tests.h
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
#ifndef BLISS_INDEX_TESTS_H
#define BLISS_INDEX_TESTS_H
#include "include/pgm/pgm_index_dynamic.hpp"
#include <alex.h>
#include <gtest/gtest.h>
#include <lipp.h>
#include <spdlog/common.h>
#include "include/pgm/pgm_index_dynamic.hpp"

#include <algorithm>
#include <cxxopts.hpp>
#include <iostream>
#include <string>
#include <algorithm>
#include <random>
#include <string>

#include "bliss/bench_pgm.h"
#include "bliss/bench_alex.h"
#include "bliss/bench_art.h"
#include "bliss/bench_btree.h"
#include "bliss/bench_lipp.h"
#include "bliss/bench_pgm.h"
#include "bliss/bliss_index.h"
#include "bliss/util/args.h"
#include "bliss/util/config.h"
Expand All @@ -28,20 +29,25 @@ using namespace bliss::utils;
using key_type = unsigned long;
using value_type = unsigned long;

class BlissIndexTest : public testing::Test {
protected:
class BlissIndexTest : public testing::Test
{
protected:
std::unique_ptr<bliss::BlissIndex<key_type, value_type>> index;
std::string indexes[4] = {"alex", "lipp", "btree", "pgm"};
std::string indexes[5] = {"alex", "lipp", "btree", "pgm", "art"};
int num_keys = 100000;

void SetUp() {}
void SetUp()
{
}

void GenerateData(std::vector<key_type> &data, int num_keys,
bool sorted = true) {
for (int i = 0; i < num_keys; i++) {
void GenerateData(std::vector<key_type> &data, int num_keys, bool sorted = true)
{
for (int i = 0; i < num_keys; i++)
{
data.push_back(i);
}
if (!sorted) {
if (!sorted)
{
std::random_device rd;
std::mt19937 g(rd());
std::shuffle(data.begin(), data.end(), g);
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})
42 changes: 42 additions & 0 deletions tests/test_art/art_tests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include "bliss_index_tests.h"

class ArtTest : public BlissIndexTest {};


TEST_F(ArtTest, TestArt_Sanity) {
index.reset(new bliss::BlissARTIndex<key_type, key_type>());
std::vector<key_type> data;
int key = 100'000;
int value = 123'456;
index->put(key, value);
EXPECT_TRUE(index->get(key));
}


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 2b9cf5c

Please sign in to comment.