Skip to content

Commit

Permalink
range queries add
Browse files Browse the repository at this point in the history
  • Loading branch information
JslYoon committed Feb 20, 2025
1 parent 279bd6a commit 9f13463
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/bliss/bench_alex.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ class BlissAlexIndex : public BlissIndex<KEY_TYPE, VALUE_TYPE> {
}

bool get(KEY_TYPE start, KEY_TYPE end) override {
throw std::runtime_error("Not implemented");
auto it_start = _index.lower_bound(start);
auto it_end = _index.lower_bound(end);
// Return true if there are any elements in the range
return it_start != _index.end() && it_start != it_end;
}

void put(KEY_TYPE key, VALUE_TYPE value) override {
Expand Down
4 changes: 3 additions & 1 deletion src/bliss/bench_btree.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ class BlissBTreeIndex : public BlissIndex<KEY_TYPE, VALUE_TYPE> {
bool get(KEY_TYPE key) override { return this->_index.exists(key); }

bool get(KEY_TYPE start, KEY_TYPE end) override {
throw std::runtime_error("Not implemented");
auto start_it = this->_index.lower_bound(start);
auto end_it = this->_index.upper_bound(end);
return start_it != end_it;
}

void put(KEY_TYPE key, VALUE_TYPE value) override {
Expand Down
1 change: 0 additions & 1 deletion src/bliss_bench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "bliss/bench_alex.h"
#include "bliss/bench_art.h"
#include "bliss/bench_btree.h"
#include "bliss/bench_csbtree.h"
#include "bliss/bench_leveldb.h"
#include "bliss/bench_lipp.h"
#include "bliss/bench_pgm.h"
Expand Down
12 changes: 12 additions & 0 deletions tests/test_alex/alex_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,16 @@ TEST_F(AlexTest, TestAlex_Random) {
for (auto key : data) {
EXPECT_TRUE(index->get(key));
}
}

TEST_F(AlexTest, TestAlex_RangeQueries) {
index.reset(new bliss::BlissAlexIndex<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);

EXPECT_TRUE(index->get(data[5], data[10]));
}
12 changes: 12 additions & 0 deletions tests/test_btree/btree_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,16 @@ TEST_F(BTreeTest, TestBTree_Random) {
for (auto key : data) {
EXPECT_TRUE(index->get(key));
}
}

TEST_F(BTreeTest, TestBTree_RangeQueries) {
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);

EXPECT_TRUE(index->get(data[5], data[10]));
}

0 comments on commit 9f13463

Please sign in to comment.