#arithmetic-coding #adaptive

bin+lib redux

Adaptive arithmetic compression library written in Rust

2 unstable releases

Uses old Rust 2015

0.2.0 Mar 12, 2017
0.1.0 Feb 28, 2016

#442 in Compression

MIT license

5.5MB
1.5K SLoC

Rust 1K SLoC // 0.0% comments C 371 SLoC // 0.1% comments Common Lisp 81 SLoC

Contains (ELF exe/lib, 39KB) resources/canterbury/sum

Redux - Adaptive Arithmetic Compression Library Written in Rust

Build Status Crates.io

Overview

This crate implements adaptive arithmetic coding algorithm. Written entirely in Rust programming language.


lib.rs:

Adaptive arithmetic compression library.

This crate provides standard arithmetic coding implementation that can use customized symbol probability models. This crate offers two adaptive models: AdaptiveLinearModel and AdaptiveTreeModel. Adaptive models continuously update the symbol probability distribution with each encoded symbol.

  • AdaptiveLinearModel is a straightforward, but slow implementation, present mainly for tasting and benchmarking purposes.

  • AdaptiveTreeModel is a Fenwick tree-based implementation, it is advised to use this model for any uses.

It is possible to use a custom model (it may or may not be adaptive) by implementing the model::Model trait.

Examples

Any byte stream can be encoded and decoded that implements the std::io::Read trait, and the output can be anything that implements std::io::Write trait. Thus, it is possible to process files or memory objects as well.

use redux::model::*;

let data = vec![0x72u8, 0x65u8, 0x64u8, 0x75u8, 0x78u8];

// Encode
let mut cursor1 = std::io::Cursor::new(&data);
let mut compressed = Vec::<u8>::new();
assert!(redux::compress(&mut cursor1, &mut compressed, AdaptiveTreeModel::new(Parameters::new(8, 14, 16).unwrap())).is_ok());

// Decode
let mut cursor2 = std::io::Cursor::new(&compressed);
let mut decompressed = Vec::<u8>::new();
assert!(redux::decompress(&mut cursor2, &mut decompressed, AdaptiveTreeModel::new(Parameters::new(8, 14, 16).unwrap())).is_ok());

assert_eq!(decompressed, data);

No runtime deps