Crates.io | pco |
lib.rs | pco |
version | 0.4.6 |
created_at | 2023-07-07 23:30:38.285683+00 |
updated_at | 2025-06-22 16:45:49.954978+00 |
description | Good compression for numerical sequences |
homepage | |
repository | https://github.com/pcodec/pcodec |
max_upload_size | |
id | 911222 |
size | 338,972 |
Pco (Pcodec) losslessly compresses and decompresses numerical sequences with high compression ratio and moderately fast speed.
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(())
}
**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:
~/.cargo/config.toml
:[target.'cfg(target_arch = "x86_64")']
rustflags = ["-C", "target-feature=+bmi1,+bmi2,+avx2"]
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.