Skip to content

Commit

Permalink
Add learned index (RadixSpline) Rust bindings (#511)
Browse files Browse the repository at this point in the history
Add end to end tpch benchmarking code
add build script that compiles and links c++ radixspline library
add safe rust module for running radixspline

Note: may need to manually delete radixspline.o and libradixspline.a
from sandbox/qe/RadixSplineLib to force recompilation when changes are
made to the C++ radixspline code.

---------

Co-authored-by: Geoffrey Yu <[email protected]>
  • Loading branch information
xingalbert and geoffxy authored Sep 11, 2024
1 parent 2070775 commit d9c8ec6
Show file tree
Hide file tree
Showing 18 changed files with 665 additions and 42 deletions.
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

0 comments on commit d9c8ec6

Please sign in to comment.