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

Add learned index (RadixSpline) Rust bindings #511

Merged
merged 13 commits into from
Sep 11, 2024
Merged
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,7 @@ sandbox/qe/.brad_qe_repl_history
# BRAD UI.
ui/dist/
ui/node_modules/

*.tmp
*.o
*.a
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "sandbox/qe/RadixSpline"]
path = sandbox/qe/RadixSpline
url = https://github.com/learnedsystems/RadixSpline
142 changes: 140 additions & 2 deletions sandbox/qe/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 14 additions & 3 deletions sandbox/qe/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
name = "brad_qe"
version = "0.1.0"
edition = "2021"
# NOTE: This currently does not work. (C++ standard library linking error)
# build = "build.rs"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand All @@ -14,11 +16,20 @@ arrow = "50.0.0"
rustyline = "10.0.0"
rand = { version = "0.8.5", features = ["small_rng"] }
csv = "1.3.0"
cty = "0.2.2"

[[bin]]
name = "brad_qe_repl"
path = "src/bin/repl.rs"
[build-dependencies]
bindgen = "0.69.4"
cc = "1.0.96"

[[bin]]
name = "bench_q3"
path = "src/bin/bench_q3.rs"

[[bin]]
name = "brad_qe_repl"
path = "src/bin/repl.rs"

# [[bin]]
# name = "test_radixspline"
# path = "src/bin/test_radixspline.rs"
1 change: 1 addition & 0 deletions sandbox/qe/RadixSpline
Submodule RadixSpline added at ab96aa
27 changes: 27 additions & 0 deletions sandbox/qe/RadixSplineLib/radixspline.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include "radixspline.h"

void* build(const uint64_t* ks, uint64_t size) {
RSData* rs = new RSData;
rs->keys = std::vector<uint64_t>(size);
memcpy(rs->keys.data(), ks, size * sizeof(uint64_t));
uint64_t min = rs->keys.front();
uint64_t max = rs->keys.back();
rs::Builder<uint64_t> rsb(min, max);
for (const auto& key : rs->keys) rsb.AddKey(key);
rs::RadixSpline<uint64_t> rso = rsb.Finalize();
rs->rspline = rso;
return (void*)rs;
}

bool lookup(void* ptr, uint64_t key) {
RSData* rs = (RSData*) ptr;
rs::SearchBound bound = rs->rspline.GetSearchBound(key);
auto start = begin(rs->keys) + bound.begin, last = begin(rs->keys) + bound.end;
auto iter = std::lower_bound(start, last, key);
return iter != rs->keys.end() && *iter == key;
}

void clear(void* ptr) {
RSData* rs = (RSData*) ptr;
delete rs;
}
18 changes: 18 additions & 0 deletions sandbox/qe/RadixSplineLib/radixspline.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "../RadixSpline/include/rs/builder.h"
#include <string.h>


struct RSData {
std::vector<uint64_t> keys;
rs::RadixSpline<uint64_t> rspline;
};

extern "C" {

int32_t add(int32_t a, int32_t b);
void* build(const uint64_t* ks, uint64_t size);

bool lookup(void* ptr, uint64_t key);

void clear(void* ptr);
}
Loading