delta-encoding

Crates.iodelta-encoding
lib.rsdelta-encoding
version0.4.0
sourcesrc
created_at2022-06-30 01:41:34.474208
updated_at2022-07-03 00:48:23.391474
descriptionA library to encode and decode a delta-encoded stream of numbers
homepage
repositoryhttps://github.com/nyurik/delta-encoding
max_upload_size
id616107
size24,433
Yuri Astrakhan (nyurik)

documentation

README

geo on Crates.io Coverage Status Documentation

Delta-Encoding library

A simple library for encoding and decoding a stream of values as delta-encoded. For example, if you have a stream of values like this:

1, 3, 2, 4, 5

the delta-encoded stream would be:

1, 2, -1, 2, 1

Usage

use delta_encoding::{DeltaEncoderExt, DeltaDecoderExt};

pub fn main() {
    let data = vec![1, 2, 5, 4, 2];

    // Delta-encode without consuming, and without making a vector copy
    let encoded: Vec<i64> = data.iter().copied().deltas().collect();
    assert_eq!(encoded, vec![1, 1, 3, -1, -2]);

    // Consume and delta-encode
    let encoded: Vec<i64> = data.into_iter().deltas().collect();
    assert_eq!(encoded, vec![1, 1, 3, -1, -2]);

    let data = vec![1, 1, 3, -1, -2];

    // Delta-decode without consuming, and without making a vector copy
    let decoded: Vec<i64> = data.iter().copied().original().collect();
    assert_eq!(decoded, vec![1, 2, 5, 4, 2]);

    // Consume and delta-decode
    let decoded: Vec<i64> = data.into_iter().original().collect();
    assert_eq!(decoded, vec![1, 2, 5, 4, 2]);
}

Development

All of these must succeed:

cargo test    # Testing
cargo bench   # Benchmarking
cargo fmt     # Code format
cargo clippy  # Code lints
Commit count: 13

cargo fmt