-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
135 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |