Module intvec

Source
Expand description

§Compressed IntVec

This module provides the IntVec structure for efficiently compressing a series of u64 values using a specified instantaneous code from the dsi-bitstream crate.

§How It Works

The IntVec structure compresses a series of u64 values by encoding them with a specified codec. Every kth element is sampled during encoding, meaning its bit-offset is recorded. This sampling information allows the decoder to jump directly to the vicinity of any desired element, thereby minimizing the number of bits that need to be processed during random access.

§Features

  • Efficient Compression: Reduces storage requirements by encoding data into a compact bitstream.
  • Fast Random Access: Leverages sampled bit-offsets to quickly decode individual elements.
  • Iterative Decoding: Provides an iterator that decodes values on the fly for sequential access.

§Example Usage

use compressed_intvec::intvec::IntVec;
use compressed_intvec::codecs::GammaCodec;
use dsi_bitstream::traits::BE;

let input = vec![1, 2, 3, 4, 5, 6, 7, 8];
let sampling_rate = 2;
let intvec = IntVec::<BE, _, GammaCodec>::from(&input, sampling_rate).unwrap();

// Fast random access using the sampled bit offsets
assert_eq!(intvec.get(3), 4);

// Decode the entire vector back to its original form
let decompressed: Vec<u64> = intvec.into_vec();
assert_eq!(decompressed, input);

§Type Aliases

For convenience, this module provides type aliases for common configurations:

  • BEIntVec: A big-endian version of the compressed vector.

    use compressed_intvec::intvec::BEIntVec;
    use compressed_intvec::codecs::GammaCodec;
    
    let input = vec![10, 20, 30];
    let intvec = BEIntVec::<GammaCodec>::from(&input, 2).unwrap();
  • LEIntVec: A little-endian version of the compressed vector.

    use compressed_intvec::intvec::LEIntVec;
    use compressed_intvec::codecs::GammaCodec;
    
    let input = vec![9, 8, 7];
    let intvec = LEIntVec::<GammaCodec>::from(&input, 2).unwrap();

Structs§

IntVec
A compressed vector of unsigned 64-bit integers using a specified codec.
IntVecIter
An iterator for the IntVec structure.

Type Aliases§

BEIntVec
Type alias for an IntVec with big-endian encoding and a default codec.
LEIntVec
Type alias for an IntVec with little-endian encoding and a default codec.