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

Jslyoon/new skip list #41

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
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_skiplist.h
)

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

target_include_directories(bliss PUBLIC
Expand Down
18 changes: 16 additions & 2 deletions external/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ FetchContent_MakeAvailable(cxxopts)

FetchContent_Declare(
alex
GIT_REPOSITORY https://github.com/microsoft/ALEX.git
GIT_REPOSITORY https://github.com/microsoft/ALEX
GIT_TAG master
)
FetchContent_GetProperties(alex)
Expand Down Expand Up @@ -70,4 +70,18 @@ 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(
skiplist
GIT_REPOSITORY https://github.com/petegoodliffe/skip_list
GIT_TAG master
)
FetchContent_GetProperties(skiplist)
if (NOT skiplist_POPULATED)
FetchContent_Populate(skiplist)
endif()

add_library(skiplist INTERFACE)
target_include_directories(skiplist INTERFACE ${skiplist_SOURCE_DIR})
34 changes: 34 additions & 0 deletions src/bliss/bench_skiplist.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#ifndef BLISS_BENCH_SKIPLIST
#define BLISS_BENCH_SKIPLIST

#include <vector>

#include "bliss/bliss_index.h"
#include "skip_list.h"

namespace bliss {

template <typename KEY_TYPE, typename VALUE_TYPE>
class BlissSkipListIndex : public BlissIndex<KEY_TYPE, VALUE_TYPE> {
public:

goodliffe::skip_list<KEY_TYPE> _index;
BlissSkipListIndex() : _index(){};

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

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

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

void end_routine() override {}
};

} // namespace bliss

#endif // !BLISS_BENCH_SKIPLIST
4 changes: 4 additions & 0 deletions src/bliss_bench.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <alex.h>
#include <lipp.h>
#include "skip_list.h"
#include <spdlog/common.h>

#include <cxxopts.hpp>
Expand All @@ -9,6 +10,7 @@
#include "bliss/bench_alex.h"
#include "bliss/bench_btree.h"
#include "bliss/bench_lipp.h"
#include "bliss/bench_skiplist.h"
#include "bliss/bliss_index.h"
#include "bliss/util/args.h"
#include "bliss/util/config.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 == "skiplist") {
index.reset(new bliss::BlissSkipListIndex<key_type, value_type>());
} else {
spdlog::error(config.index + " not implemented yet", 1);
}
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_skiplist)
9 changes: 7 additions & 2 deletions tests/bliss_index_tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@
#include <cxxopts.hpp>
#include <iostream>
#include <string>
#include <algorithm>
#include <random>

#include "bliss/bench_alex.h"
#include "bliss/bench_btree.h"
#include "bliss/bench_lipp.h"
#include "bliss/bench_skiplist.h"
#include "bliss/bliss_index.h"
#include "bliss/util/args.h"
#include "bliss/util/config.h"
Expand All @@ -27,7 +30,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", "skiplist"};
int num_keys = 100000;

void SetUp() {}
Expand All @@ -38,7 +41,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
2 changes: 1 addition & 1 deletion tests/test_lipp/lipp_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ TEST_F(LippTest, TestLipp_Sorted) {
}

TEST_F(LippTest, TestLipp_Random) {
index.reset(new bliss::BlissAlexIndex<key_type, key_type>());
index.reset(new bliss::BlissLippIndex<key_type, key_type>());
std::vector<key_type> data;
GenerateData(data, num_keys, false);

Expand Down
9 changes: 9 additions & 0 deletions tests/test_skiplist/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_skiplist/skiplist_tests.cpp
JslYoon marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include "bliss_index_tests.h"

class SkipListTest : public BlissIndexTest {};

TEST_F(SkipListTest, TestSkipList_Sorted) {
index.reset(new bliss::BlissSkipListIndex<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(SkipListTest, TestSkipList_Random) {
index.reset(new bliss::BlissSkipListIndex<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));
}
}