Skip to content

Commit dd9a130

Browse files
authored
adding pgm index (#43)
* adding pgm index * make pgm sanity tests * clean up code * fix pgm test bug
1 parent f8a05b2 commit dd9a130

File tree

8 files changed

+125
-7
lines changed

8 files changed

+125
-7
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ add_library(bliss OBJECT
5151
${CMAKE_SOURCE_DIR}/src/bliss/bench_lipp.h
5252
${CMAKE_SOURCE_DIR}/src/bliss/bench_alex.h
5353
${CMAKE_SOURCE_DIR}/src/bliss/bench_btree.h
54+
${CMAKE_SOURCE_DIR}/src/bliss/bench_pgm.h
5455
)
5556

5657
target_compile_features(bliss PUBLIC
@@ -63,6 +64,7 @@ target_link_libraries(bliss PUBLIC
6364
alex
6465
lipp
6566
tlx
67+
pgm
6668
)
6769

6870
target_include_directories(bliss PUBLIC

external/CMakeLists.txt

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ target_include_directories(alex INTERFACE ${alex_SOURCE_DIR}/src/core)
4848

4949
FetchContent_Declare(
5050
lipp
51-
GIT_REPOSITORY https://github.com/Jiacheng-WU/lipp
51+
GIT_REPOSITORY https://github.com/Jiacheng-WU/lipp.git
5252
GIT_TAG main
5353
)
5454
FetchContent_GetProperties(lipp)
@@ -70,4 +70,20 @@ if (NOT tlx_POPULATED)
7070
endif()
7171

7272
add_library(tlx INTERFACE)
73-
target_include_directories(tlx INTERFACE ${tlx_SOURCE_DIR}/)
73+
target_include_directories(tlx INTERFACE ${tlx_SOURCE_DIR}/)
74+
75+
76+
77+
78+
FetchContent_Declare(
79+
pgm
80+
GIT_REPOSITORY https://github.com/gvinciguerra/PGM-index
81+
GIT_TAG master
82+
)
83+
FetchContent_GetProperties(pgm)
84+
if (NOT pgm_POPULATED)
85+
FetchContent_Populate(pgm)
86+
endif()
87+
88+
add_library(pgm INTERFACE)
89+
target_include_directories(pgm INTERFACE ${pgm_SOURCE_DIR})

src/bliss/bench_pgm.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#ifndef BLISS_BENCH_PGM
2+
#define BLISS_BENCH_PGM
3+
4+
#include <vector>
5+
6+
#include "bliss/bliss_index.h"
7+
#include "include/pgm/pgm_index_dynamic.hpp"
8+
9+
10+
namespace bliss {
11+
12+
template <typename KEY_TYPE, typename VALUE_TYPE>
13+
class BlissPGMIndex : public BlissIndex<KEY_TYPE, VALUE_TYPE> {
14+
public:
15+
pgm::DynamicPGMIndex<KEY_TYPE, VALUE_TYPE> _index;
16+
BlissPGMIndex() : _index(){};
17+
18+
void bulkload(
19+
std::vector<std::pair<KEY_TYPE, VALUE_TYPE>> values) override {
20+
// expects the pairs to be pre-sorted before performing bulk load
21+
for (const auto& pair : values) {
22+
this->put(pair.first, pair.second);
23+
}
24+
}
25+
26+
bool get(KEY_TYPE key) override {
27+
auto it = _index.find(key);
28+
return it != _index.end();
29+
}
30+
31+
void put(KEY_TYPE key, VALUE_TYPE value) override { _index.insert_or_assign(key, value); }
32+
33+
void end_routine() override {}
34+
};
35+
36+
} // namespace bliss
37+
38+
#endif // !BLISS_BENCH_PGM

src/bliss_bench.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
#include <alex.h>
22
#include <lipp.h>
33
#include <spdlog/common.h>
4+
#include "include/pgm/pgm_index_dynamic.hpp"
45

56
#include <cxxopts.hpp>
67
#include <iostream>
78
#include <string>
89

10+
#include "bliss/bench_pgm.h"
911
#include "bliss/bench_alex.h"
1012
#include "bliss/bench_btree.h"
1113
#include "bliss/bench_lipp.h"
@@ -168,6 +170,8 @@ int main(int argc, char *argv[]) {
168170
index.reset(new bliss::BlissLippIndex<key_type, value_type>());
169171
} else if (config.index == "btree") {
170172
index.reset(new bliss::BlissBTreeIndex<key_type, value_type>());
173+
} else if (config.index == "pgm") {
174+
index.reset(new bliss::BlissPGMIndex<key_type, value_type>());
171175
} else {
172176
spdlog::error(config.index + " not implemented yet", 1);
173177
}

tests/bliss_index_tests.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@
44
#include <gtest/gtest.h>
55
#include <lipp.h>
66
#include <spdlog/common.h>
7+
#include "include/pgm/pgm_index_dynamic.hpp"
78

89
#include <cxxopts.hpp>
910
#include <iostream>
1011
#include <string>
12+
#include <algorithm>
13+
#include <random>
1114

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

3337
void SetUp() {}
@@ -38,7 +42,9 @@ class BlissIndexTest : public testing::Test {
3842
data.push_back(i);
3943
}
4044
if (!sorted) {
41-
std::random_shuffle(data.begin(), data.end());
45+
std::random_device rd;
46+
std::mt19937 g(rd());
47+
std::shuffle(data.begin(), data.end(), g);
4248
}
4349
}
4450
};

tests/test_btree/btree_tests.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#include "bliss_index_tests.h"
22

3-
class BTreeTest : public BlissIndexTest {};
3+
class PGMTest : public BlissIndexTest {};
44

5-
TEST_F(BTreeTest, TestBTree_Sorted) {
5+
TEST_F(PGMTest, TestPGM_Sorted) {
66
index.reset(new bliss::BlissBTreeIndex<key_type, key_type>());
77
std::vector<key_type> data;
88
GenerateData(data, num_keys);
@@ -16,7 +16,7 @@ TEST_F(BTreeTest, TestBTree_Sorted) {
1616
}
1717
}
1818

19-
TEST_F(BTreeTest, TestBTree_Random) {
19+
TEST_F(PGMTest, TestPGM_Random) {
2020
index.reset(new bliss::BlissBTreeIndex<key_type, key_type>());
2121
std::vector<key_type> data;
2222
GenerateData(data, num_keys, false);

tests/test_pgm/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
get_filename_component(EXEC ${CMAKE_CURRENT_SOURCE_DIR} NAME)
2+
file(GLOB_RECURSE CPP_TESTS "*_tests.cpp")
3+
add_executable(${EXEC} ${CPP_TESTS})
4+
target_link_libraries(${EXEC} PRIVATE
5+
bliss
6+
bliss_test_infra
7+
GTest::gtest_main)
8+
include(GoogleTest)
9+
gtest_discover_tests(${EXEC})

tests/test_pgm/pgm_tests.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#include "bliss_index_tests.h"
2+
3+
class PGMTest : public BlissIndexTest {};
4+
5+
6+
TEST_F(PGMTest, TestPGM_Sanity) {
7+
index.reset(new bliss::PGMIndex<key_type, key_type>());
8+
std::vector<key_type> data;
9+
int key = 100'000;
10+
int value = 123'456;
11+
index->put(key, value);
12+
EXPECT_TRUE(index->get(key));
13+
}
14+
15+
16+
TEST_F(PGMTest, TestPGM_Sorted) {
17+
index.reset(new bliss::PGMIndex<key_type, key_type>());
18+
std::vector<key_type> data;
19+
GenerateData(data, num_keys);
20+
21+
auto insert_start = data.begin();
22+
auto insert_end = data.end();
23+
executor::execute_inserts(*index, insert_start, insert_end);
24+
25+
for (auto key : data) {
26+
EXPECT_TRUE(index->get(key));
27+
}
28+
}
29+
30+
31+
TEST_F(PGMTest, TestPGM_Random) {
32+
index.reset(new bliss::PGMIndex<key_type, key_type>());
33+
std::vector<key_type> data;
34+
GenerateData(data, num_keys, false);
35+
36+
auto insert_start = data.begin();
37+
auto insert_end = data.end();
38+
executor::execute_inserts(*index, insert_start, insert_end);
39+
40+
for (auto key : data) {
41+
EXPECT_TRUE(index->get(key));
42+
}
43+
}

0 commit comments

Comments
 (0)