18 releases

new 0.4.2 Feb 11, 2025
0.4.1 Nov 23, 2024
0.3.1 Jul 6, 2024
0.2.2 Mar 22, 2024
0.0.0-alpha.0 Jul 7, 2023

#36 in Compression

Download history 192/week @ 2024-10-22 237/week @ 2024-10-29 508/week @ 2024-11-05 281/week @ 2024-11-12 480/week @ 2024-11-19 275/week @ 2024-11-26 221/week @ 2024-12-03 253/week @ 2024-12-10 162/week @ 2024-12-17 95/week @ 2024-12-24 55/week @ 2024-12-31 113/week @ 2025-01-07 174/week @ 2025-01-14 501/week @ 2025-01-21 847/week @ 2025-01-28 449/week @ 2025-02-04

1,986 downloads per month
Used in 8 crates (7 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: Vec<i64> = simple_decompress(&compressed)?;
  assert_eq!(recovered, my_nums);
  Ok(())
}

Compilation Notes

**For best performance on x86_64, compile with bmi1, bmi2, and avx2. This improves compression speed slightly and decompression speed substantially! Almost all hardware nowadays supports these instruction sets. 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 setting 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