Skip to content

Commit

Permalink
adding pgm index (#43)
Browse files Browse the repository at this point in the history
* adding pgm index

* make pgm sanity tests

* clean up code

* fix pgm test bug
  • Loading branch information
JslYoon authored Jan 21, 2025
1 parent f8a05b2 commit dd9a130
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 7 deletions.
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_pgm.h
)

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

target_include_directories(bliss PUBLIC
Expand Down
20 changes: 18 additions & 2 deletions external/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ target_include_directories(alex INTERFACE ${alex_SOURCE_DIR}/src/core)

FetchContent_Declare(
lipp
GIT_REPOSITORY https://github.com/Jiacheng-WU/lipp
GIT_REPOSITORY https://github.com/Jiacheng-WU/lipp.git
GIT_TAG main
)
FetchContent_GetProperties(lipp)
Expand All @@ -70,4 +70,20 @@ 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}/)




FetchContent_Declare(
pgm
GIT_REPOSITORY https://github.com/gvinciguerra/PGM-index
GIT_TAG master
)
FetchContent_GetProperties(pgm)
if (NOT pgm_POPULATED)
FetchContent_Populate(pgm)
endif()

add_library(pgm INTERFACE)
target_include_directories(pgm INTERFACE ${pgm_SOURCE_DIR})
38 changes: 38 additions & 0 deletions src/bliss/bench_pgm.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#ifndef BLISS_BENCH_PGM
#define BLISS_BENCH_PGM

#include <vector>

#include "bliss/bliss_index.h"
#include "include/pgm/pgm_index_dynamic.hpp"


namespace bliss {

template <typename KEY_TYPE, typename VALUE_TYPE>
class BlissPGMIndex : public BlissIndex<KEY_TYPE, VALUE_TYPE> {
public:
pgm::DynamicPGMIndex<KEY_TYPE, VALUE_TYPE> _index;
BlissPGMIndex() : _index(){};

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) {
this->put(pair.first, pair.second);
}
}

bool get(KEY_TYPE key) override {
auto it = _index.find(key);
return it != _index.end();
}

void put(KEY_TYPE key, VALUE_TYPE value) override { _index.insert_or_assign(key, value); }

void end_routine() override {}
};

} // namespace bliss

#endif // !BLISS_BENCH_PGM
4 changes: 4 additions & 0 deletions src/bliss_bench.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#include <alex.h>
#include <lipp.h>
#include <spdlog/common.h>
#include "include/pgm/pgm_index_dynamic.hpp"

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

#include "bliss/bench_pgm.h"
#include "bliss/bench_alex.h"
#include "bliss/bench_btree.h"
#include "bliss/bench_lipp.h"
Expand Down Expand Up @@ -168,6 +170,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 == "pgm") {
index.reset(new bliss::BlissPGMIndex<key_type, value_type>());
} else {
spdlog::error(config.index + " not implemented yet", 1);
}
Expand Down
10 changes: 8 additions & 2 deletions tests/bliss_index_tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@
#include <gtest/gtest.h>
#include <lipp.h>
#include <spdlog/common.h>
#include "include/pgm/pgm_index_dynamic.hpp"

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

#include "bliss/bench_pgm.h"
#include "bliss/bench_alex.h"
#include "bliss/bench_btree.h"
#include "bliss/bench_lipp.h"
Expand All @@ -27,7 +31,7 @@ using value_type = unsigned long;
class BlissIndexTest : public testing::Test {
protected:
std::unique_ptr<bliss::BlissIndex<key_type, value_type>> index;
std::string indexes[3] = {"alex", "lipp", "btree"};
std::string indexes[4] = {"alex", "lipp", "btree", "pgm"};
int num_keys = 100000;

void SetUp() {}
Expand All @@ -38,7 +42,9 @@ class BlissIndexTest : public testing::Test {
data.push_back(i);
}
if (!sorted) {
std::random_shuffle(data.begin(), data.end());
std::random_device rd;
std::mt19937 g(rd());
std::shuffle(data.begin(), data.end(), g);
}
}
};
Expand Down
6 changes: 3 additions & 3 deletions tests/test_btree/btree_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "bliss_index_tests.h"

class BTreeTest : public BlissIndexTest {};
class PGMTest : public BlissIndexTest {};

TEST_F(BTreeTest, TestBTree_Sorted) {
TEST_F(PGMTest, TestPGM_Sorted) {
index.reset(new bliss::BlissBTreeIndex<key_type, key_type>());
std::vector<key_type> data;
GenerateData(data, num_keys);
Expand All @@ -16,7 +16,7 @@ TEST_F(BTreeTest, TestBTree_Sorted) {
}
}

TEST_F(BTreeTest, TestBTree_Random) {
TEST_F(PGMTest, TestPGM_Random) {
index.reset(new bliss::BlissBTreeIndex<key_type, key_type>());
std::vector<key_type> data;
GenerateData(data, num_keys, false);
Expand Down
9 changes: 9 additions & 0 deletions tests/test_pgm/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})
43 changes: 43 additions & 0 deletions tests/test_pgm/pgm_tests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include "bliss_index_tests.h"

class PGMTest : public BlissIndexTest {};


TEST_F(PGMTest, TestPGM_Sanity) {
index.reset(new bliss::PGMIndex<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(PGMTest, TestPGM_Sorted) {
index.reset(new bliss::PGMIndex<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(PGMTest, TestPGM_Random) {
index.reset(new bliss::PGMIndex<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 dd9a130

Please sign in to comment.