#varint #numbers #stream #simd #port #variable-length

stream-vbyte

Compress and decompress numbers efficiently in the Stream VByte encoding

7 unstable releases

0.4.1 May 23, 2023
0.4.0 Nov 27, 2021
0.3.2 Oct 12, 2017
0.2.0 Oct 4, 2017
0.1.0 Sep 30, 2017

#180 in Encoding

Download history 2180/week @ 2023-12-13 2847/week @ 2023-12-20 1102/week @ 2023-12-27 2648/week @ 2024-01-03 2655/week @ 2024-01-10 2964/week @ 2024-01-17 2770/week @ 2024-01-24 1644/week @ 2024-01-31 1710/week @ 2024-02-07 2298/week @ 2024-02-14 2443/week @ 2024-02-21 2635/week @ 2024-02-28 1886/week @ 2024-03-06 2576/week @ 2024-03-13 2513/week @ 2024-03-20 1642/week @ 2024-03-27

9,049 downloads per month
Used in granne

Custom license

155KB
2K SLoC

Build Status

A port of Stream VByte to Rust.

Stream VByte is a variable-length unsigned int encoding designed to make SIMD processing more efficient.

See https://lemire.me/blog/2017/09/27/stream-vbyte-breaking-new-speed-records-for-integer-compression/ and https://arxiv.org/pdf/1709.08990.pdf for details on the format. The reference C implementation is https://github.com/lemire/streamvbyte.

Usage

See the documentation.

Play with the CLI example

There's a cli.rs example provided that demonstrates encoding and decoding.

To encode some numbers, provide numbers (one per line) to stdin, and the encoded result will be written to stdout.

Example using jot to produce the numbes 1 to 100: jot 100 | cargo run --example cli -- enc | base64

Output, with cargo build output removed (the "Encoded ..." is on stderr for human convenience):

Encoded 100 numbers
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8g
ISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZ
WltcXV5fYGFiY2Q=

There's a corresponding decode mode that reads the encoded format on stdin and emits the contents, one number per line. Here, we encode some numbers then decode them again: jot 10 | cargo run --example cli -- enc | cargo run --example cli -- dec -c 10

Encoded 10 numbers
1
2
3
4
5
6
7
8
9
10
Decoded 10 numbers

Maintainers

To generate the lookup tables:

cargo run --example generate_decode_table > tmp/tables.rs && mv tmp/tables.rs src/tables.rs

To run the tests (on recent Intel):

RUSTFLAGS='-C target-feature=+ssse3,+sse4.1' cargo +nightly test --all-features

To run the benchmarks:

RUSTFLAGS='-C target-feature=+ssse3,+sse4.1' cargo +nightly bench --all-features

No runtime deps