Skip to content

Commit

Permalink
adding csbtree
Browse files Browse the repository at this point in the history
  • Loading branch information
JslYoon committed Feb 15, 2025
1 parent ba43e8c commit ef6bfeb
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ add_library(bliss OBJECT
${CMAKE_SOURCE_DIR}/src/bliss/bench_pgm.h
${CMAKE_SOURCE_DIR}/src/bliss/bench_art.h
${CMAKE_SOURCE_DIR}/src/bliss/bench_leveldb.h
${CMAKE_SOURCE_DIR}/src/bliss/bench_csbtree.h
)

target_compile_features(bliss PUBLIC
Expand All @@ -74,6 +75,7 @@ target_link_libraries(bliss PUBLIC
skiplist
pgm
art
csbtree
)

target_include_directories(bliss PUBLIC
Expand Down
17 changes: 16 additions & 1 deletion external/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,19 @@ 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})



FetchContent_Declare(
csbtree
GIT_REPOSITORY https://github.com/Arjunbala/CSBTreesConcurrency
GIT_TAG master
)
FetchContent_GetProperties(csbtree)
if (NOT csbtree_POPULATED)
FetchContent_Populate(csbtree)
endif()

add_library(csbtree INTERFACE)
target_include_directories(csbtree INTERFACE ${csbtree_SOURCE_DIR})
62 changes: 62 additions & 0 deletions src/bliss/bench_csbtree.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#ifndef BLISS_BENCH_CSBTREE_H
#define BLISS_BENCH_CSBTREE_H

#include <vector>
#include "bliss/bliss_index.h"
#include "src/vanilla_implementation/csbtree.h"

namespace bliss {

// Concrete implementation of CSBTree
class ConcreteCSBTree : public CSBTree {
public:
ConcreteCSBTree(int order) : CSBTree(order) {
root = new CSBNode(order);
}

int insert(uint64_t key) override {
if (!root->checkPresenceOfKey(key)) {
int index = root->getIndex(key);
return root->addKeyToNode(key, index);
}
return 0;
}

int del(uint64_t key) override {
return root->deleteKeyFromNode(key);
}
};

template <typename KEY_TYPE, typename VALUE_TYPE>
class BlissCSBTreeIndex : public BlissIndex<KEY_TYPE, VALUE_TYPE> {
public:
BlissCSBTreeIndex() : _index(16) {}

void bulkload(std::vector<std::pair<KEY_TYPE, VALUE_TYPE>> values) override {
for (const auto& kv : values) {
put(kv.first, 0);
}
}

bool get(KEY_TYPE key) override {
uint64_t k = static_cast<uint64_t>(key);
return _index.root->checkPresenceOfKey(k);
}

bool get(KEY_TYPE start, KEY_TYPE end) override {
throw std::runtime_error("Not implemented");
}

void put(KEY_TYPE key, VALUE_TYPE) override {
uint64_t k = static_cast<uint64_t>(key);
_index.insert(k);
}

void end_routine() override {}

private:
ConcreteCSBTree _index;
};

} // namespace bliss
#endif // BLISS_BENCH_CSBTREE_H
3 changes: 3 additions & 0 deletions src/bliss_bench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "bliss/bench_lipp.h"
#include "bliss/bench_pgm.h"
#include "bliss/bench_skiplist.h"
#include "bliss/bench_csbtree.h"
#include "bliss/bliss_index.h"
#include "bliss/util/args.h"
#include "bliss/util/config.h"
Expand Down Expand Up @@ -182,6 +183,8 @@ int main(int argc, char *argv[]) {
index.reset(new bliss::BlissPGMIndex<key_type, value_type>());
} else if (config.index == "leveldb") {
index.reset(new bliss::BlissLevelDBIndex<key_type, value_type>());
} else if (config.index == "csbtree") {
index.reset(new bliss::BlissLevelDBIndex<key_type, value_type>());
} else {
spdlog::error(config.index + " not implemented yet", 1);
}
Expand Down
5 changes: 3 additions & 2 deletions tests/bliss_index_tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "bliss/bench_lipp.h"
#include "bliss/bench_pgm.h"
#include "bliss/bench_skiplist.h"
#include "bliss/bench_csbtree.h"
#include "bliss/bliss_index.h"
#include "bliss/util/args.h"
#include "bliss/util/config.h"
Expand All @@ -34,8 +35,8 @@ using value_type = unsigned long;
class BlissIndexTest : public testing::Test {
protected:
std::unique_ptr<bliss::BlissIndex<key_type, value_type>> index;
std::string indexes[7] = {"alex", "lipp", "btree", "skiplist",
"pgm", "art", "leveldb"};
std::string indexes[8] = {"alex", "lipp", "btree", "skiplist",
"pgm", "art", "leveldb", "csbtree"};

int num_keys = 100000;

Expand Down
9 changes: 9 additions & 0 deletions tests/test_csbtree/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})
40 changes: 40 additions & 0 deletions tests/test_csbtree/csbtree_tests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include "bliss_index_tests.h"

class CSBTreeTest : public BlissIndexTest {};

TEST_F(CSBTreeTest, TestCSBTree_Sanity) {
index.reset(new bliss::BlissCSBTreeIndex<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(CSBTreeTest, TestCSBTree_Sorted) {
index.reset(new bliss::BlissCSBTreeIndex<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(CSBTreeTest, TestCSBTree_Random) {
index.reset(new bliss::BlissCSBTreeIndex<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 ef6bfeb

Please sign in to comment.