Skip to content

Commit b159906

Browse files
authored
Elias Fano Improvements and Sparse Bitvectors (#27)
* Added a sparse rank/select vector that is a wrapper around Elias-Fano * implement rank0, rank1, select1, and iter1 for SparseRSVec * add select function to Elias-Fano * factored out the search functionality of the predecessor implementation to re-use it in rank queries, and successor queries, deduplicating code in Elias-Fano * added rank function to Elias-Fano benchmarks * added delta function to Elias-Fano
1 parent 51293d1 commit b159906

File tree

7 files changed

+809
-149
lines changed

7 files changed

+809
-149
lines changed

benches/elias_fano.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ fn bench_ef(b: &mut Criterion) {
3636
)
3737
});
3838

39+
group.bench_with_input(BenchmarkId::new("rank", l), &l, |b, _| {
40+
b.iter_batched(
41+
|| pred_sample.sample(&mut rng),
42+
|e| black_box(ef_vec.rank(e)),
43+
BatchSize::SmallInput,
44+
)
45+
});
46+
3947
group.bench_with_input(BenchmarkId::new("bin search", l), &l, |b, _| {
4048
b.iter_batched(
4149
|| pred_sample.sample(&mut rng),

benches/elias_fano_adversarial.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ fn bench_ef(b: &mut Criterion) {
2727

2828
// query random values from the actual sequences, to be equivalent to the worst case
2929
// benchmark below
30-
group.bench_with_input(BenchmarkId::new("uniform input", l), &l, |b, _| {
30+
group.bench_with_input(BenchmarkId::new("uniform predecessor", l), &l, |b, _| {
3131
b.iter_batched(
3232
|| sequence[query_distribution.sample(&mut rng)],
3333
|e| black_box(uniform_ef_vec.predecessor_unchecked(e)),
@@ -51,10 +51,22 @@ fn bench_ef(b: &mut Criterion) {
5151

5252
let bad_ef_vec = EliasFanoVec::from_slice(&sequence);
5353
// query random values from the actual sequences, to force long searches in the lower vec
54-
group.bench_with_input(BenchmarkId::new("adversarial input", l), &l, |b, _| {
54+
group.bench_with_input(
55+
BenchmarkId::new("adversarial predecessor", l),
56+
&l,
57+
|b, _| {
58+
b.iter_batched(
59+
|| sequence[query_distribution.sample(&mut rng)],
60+
|e| black_box(bad_ef_vec.predecessor_unchecked(e)),
61+
BatchSize::SmallInput,
62+
)
63+
},
64+
);
65+
66+
group.bench_with_input(BenchmarkId::new("adversarial rank", l), &l, |b, _| {
5567
b.iter_batched(
5668
|| sequence[query_distribution.sample(&mut rng)],
57-
|e| black_box(bad_ef_vec.predecessor_unchecked(e)),
69+
|e| black_box(bad_ef_vec.rank(e)),
5870
BatchSize::SmallInput,
5971
)
6072
});

src/bit_vec/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ use std::mem::size_of;
88

99
pub mod fast_rs_vec;
1010

11+
pub mod sparse;
12+
1113
pub mod mask;
1214

1315
/// Size of a word in bitvectors. All vectors operate on 64-bit words.

0 commit comments

Comments
 (0)