17 unstable releases (4 breaking)

0.4.1 Nov 23, 2024
0.3.1 Jul 6, 2024
0.2.2 Mar 22, 2024
0.1.2 Dec 15, 2023
0.0.0-alpha.0 Jul 7, 2023

#43 in Compression

Download history 398/week @ 2024-08-21 377/week @ 2024-08-28 271/week @ 2024-09-04 390/week @ 2024-09-11 206/week @ 2024-09-18 278/week @ 2024-09-25 120/week @ 2024-10-02 238/week @ 2024-10-09 238/week @ 2024-10-16 209/week @ 2024-10-23 247/week @ 2024-10-30 508/week @ 2024-11-06 306/week @ 2024-11-13 452/week @ 2024-11-20 253/week @ 2024-11-27 224/week @ 2024-12-04

1,288 downloads per month
Used in 7 crates (6 directly)

Apache-2.0

345KB
9K SLoC

Pco logo: a pico-scale, compressed version of the Pyramid of Khafre in the palm of your hand

Pco (Pcodec) losslessly compresses and decompresses numerical sequences with high compression ratio and moderately fast speed.

Quick Start

use pco::standalone::{simpler_compress, simple_decompress};
use pco::DEFAULT_COMPRESSION_LEVEL;
use pco::errors::PcoResult;

fn main() -> PcoResult<()> {
  // your data
  let mut my_nums = Vec::new();
  for i in 0..100000 {
    my_nums.push(i as i64);
  }

  // compress
  let compressed: Vec<u8> = simpler_compress(&my_nums, DEFAULT_COMPRESSION_LEVEL)?;
  println!("compressed down to {} bytes", compressed.len());

  // decompress
  let recovered = simple_decompress::<i64>(&compressed)?;
  println!("got back {} ints from {} to {}", recovered.len(), recovered[0], recovered.last().unwrap());
  Ok(())
}

Compilation Notes

For best performance on x86_64, compile with any bmi* and avx* instruction sets your hardware supports. Almost all x86_64 hardware these days supports bmi1, bmi2, and avx2. This improves compression speed slightly and decompression speed substantially! To make sure you're using these, you can:

  • Add the following to your ~/.cargo/config.toml:
[target.'cfg(target_arch = "x86_64")']
rustflags = ["-C", "target-feature=+bmi1,+bmi2,+avx2"]
  • OR compile with RUSTFLAGS="-C target-feature=+bmi1,+bmi2,+avx2" cargo build --release ...

Note that settings target-cpu=native does not always have the same effect, since LLVM compiles for the lowest common denominator of instructions for a broad CPU family.

Dependencies

~370KB