Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding pgm index #43

Merged
merged 4 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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})
39 changes: 39 additions & 0 deletions src/bliss/bench_pgm.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#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::PGMIndex<int, epsilon> _index();
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
8 changes: 7 additions & 1 deletion 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 Down Expand Up @@ -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})
31 changes: 31 additions & 0 deletions tests/test_pgm/pgm_tests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include "bliss_index_tests.h"

class BTreeTest : public BlissIndexTest {};

TEST_F(BTreeTest, TestBTree_Sorted) {
index.reset(new bliss::BlissBTreeIndex<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(BTreeTest, TestBTree_Random) {
index.reset(new bliss::BlissBTreeIndex<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));
}
}