Skip to main content

Crate wasm_bitpack

Crate wasm_bitpack 

Source
Expand description

wasm-bitpack is a SIMD-accelerated integer bit-packing and unpacking library with a hand-written WebAssembly SIMD128 decode fast path.

Every popular Rust integer-compression crate gets its speed from x86 AVX2/SSE intrinsics and silently falls back to scalar code when compiled to wasm32. This crate implements the missing wasm32 + simd128 decode fast path instead.

See the project README for the full pitch, benchmark methodology, and usage examples.

Structs§

Scalar
Portable, safe-Rust reference implementation of BitPacker.
Wasm128
SIMD128-accelerated BitPacker implementation.

Traits§

BitPacker
A fixed-block-size integer bit-packing codec.

Functions§

best_available
Returns the fastest BitPacker implementation available for the current compile target: Wasm128 when compiled for wasm32 with simd128 enabled, Scalar otherwise.
compress_sorted
Delta-encodes a non-decreasing (duplicates allowed) sequence and packs it into compressed, returning the number of bytes written.
compress_strictly_sorted
Delta-encodes a strictly increasing sequence and packs it into compressed, returning the number of bytes written.
decompress_sorted
Unpacks compressed (as produced by compress_sorted) into decompressed, returning the number of bytes read.
decompress_strictly_sorted
Unpacks compressed (as produced by compress_strictly_sorted) into decompressed, returning the number of bytes read.
num_bits_sorted
Returns the minimum number of bits needed to delta-encode decompressed for compress_sorted — the widest consecutive difference in a non-decreasing sequence. decompressed[0] itself is excluded (it’s stored as a raw header, not delta-encoded — see the module docs), so this reflects genuine step sizes, not decompressed[0]’s own magnitude.
num_bits_strictly_sorted
Returns the minimum number of bits needed to delta-encode decompressed for compress_strictly_sorted — the widest consecutive difference - 1 in a strictly increasing sequence. decompressed[0] itself is excluded, same as num_bits_sorted.
pack
Packs an arbitrary-length slice of u32 values into compressed at num_bits bits per value, returning the number of bytes written.
unpack
Unpacks an arbitrary-length, num_bits-packed byte buffer into decompressed, returning the number of bytes read.