Skip to content

Commit 636d770

Browse files
Merge pull request #50 from triblespace/codex/proceed-with-next-task-from-inventory
Add runnable examples
2 parents 637891c + 5462f6a commit 636d770

File tree

5 files changed

+33
-18
lines changed

5 files changed

+33
-18
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,5 @@
4949
- Fixed a typo in `bench/README.md`.
5050
- Added iterators and `to_vec` helpers for inspecting built vectors.
5151
- Split inspection tests so each assertion stands alone.
52+
- Documented `WaveletMatrix` usage in `README.md`.
53+
- Moved README usage examples to runnable files in `examples/`.

INVENTORY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
## Desired Functionality
77
- Provide more usage examples and documentation.
8+
- Add usage example demonstrating `CompactVector` construction and retrieval.
89
- Evaluate additional succinct data structures to include.
910
- Investigate alternative dense-select index strategies to replace removed `DArrayIndex`.
1011

README.md

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,9 @@ is backed by `anybytes::View`. The data can be serialized with
3030
allowing zero-copy loading from an mmap or any other source by passing the
3131
byte region to `Bytes::from_source`.
3232

33-
## Usage example
33+
## Examples
3434

35-
The snippet below shows how to build a bit vector with a rank/select index and
36-
perform a few basic queries:
37-
38-
```rust
39-
use jerky::bit_vector::*;
40-
41-
fn main() -> Result<(), Box<dyn std::error::Error>> {
42-
let mut builder = BitVectorBuilder::new();
43-
builder.extend_bits([true, false, true, false, true]);
44-
let bv = builder.freeze::<Rank9SelIndex>();
45-
46-
assert_eq!(bv.num_bits(), 5);
47-
assert_eq!(bv.rank1(4), Some(2));
48-
assert_eq!(bv.select1(1), Some(2));
49-
Ok(())
50-
}
51-
```
35+
See the [examples](examples/) directory for runnable usage demos.
5236

5337
## Licensing
5438

examples/bit_vector.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
use jerky::bit_vector::*;
2+
3+
fn main() -> Result<(), Box<dyn std::error::Error>> {
4+
let mut builder = BitVectorBuilder::new();
5+
builder.extend_bits([true, false, true, false, true]);
6+
let bv = builder.freeze::<Rank9SelIndex>();
7+
8+
assert_eq!(bv.num_bits(), 5);
9+
assert_eq!(bv.rank1(4), Some(2));
10+
assert_eq!(bv.select1(1), Some(2));
11+
Ok(())
12+
}

examples/wavelet_matrix.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
use jerky::bit_vector::Rank9SelIndex;
2+
use jerky::char_sequences::WaveletMatrix;
3+
use jerky::int_vectors::CompactVectorBuilder;
4+
5+
fn main() -> Result<(), Box<dyn std::error::Error>> {
6+
let text = "banana";
7+
let mut builder = CompactVectorBuilder::new(8)?;
8+
builder.extend(text.chars().map(|c| c as usize))?;
9+
let wm = WaveletMatrix::<Rank9SelIndex>::new(builder.freeze())?;
10+
11+
assert_eq!(wm.len(), text.len());
12+
assert_eq!(wm.access(2), Some('n' as usize));
13+
assert_eq!(wm.rank(4, 'a' as usize), Some(2));
14+
assert_eq!(wm.select(1, 'n' as usize), Some(4));
15+
Ok(())
16+
}

0 commit comments

Comments
 (0)