Skip to main content

Module bitpack

Module bitpack 

Source
Expand description

Bit-packing for small integers.

If your largest value is 15, why use 64 bits per number? Bit-packing uses only the bits you need - 4 bits for values up to 15, giving you 16x compression.

This works especially well after delta encoding sorted data, where the deltas are often tiny even when the original values are huge.

§Example

// Values [5, 2, 3, 5, 5, 8, 2] - max is 8, needs 4 bits
// Without packing: 7 * 64 = 448 bits
// With packing:    7 * 4  = 28 bits (16x smaller!)

let values = vec![5u64, 2, 3, 5, 5, 8, 2];
let packed = BitPackedInts::pack(&values);
let unpacked = packed.unpack();
assert_eq!(values, unpacked);

Structs§

BitPackedInts
Stores integers using only as many bits as the largest value needs.
DeltaBitPacked
The best compression for sorted integers - delta encoding plus bit-packing.