#encoder

delta-encoding

A library to encode and decode a delta-encoded stream of numbers

4 releases (breaking)

0.4.0 Jul 3, 2022
0.3.0 Jun 30, 2022
0.2.0 Jun 30, 2022
0.1.0 Jun 30, 2022

#109 in #encoder

Download history 4/week @ 2024-07-26 14/week @ 2024-08-02 78/week @ 2024-08-09 741/week @ 2024-08-16 648/week @ 2024-08-23 390/week @ 2024-08-30 387/week @ 2024-09-06 405/week @ 2024-09-13 449/week @ 2024-09-20 380/week @ 2024-09-27 333/week @ 2024-10-04 674/week @ 2024-10-11 537/week @ 2024-10-18 666/week @ 2024-10-25 766/week @ 2024-11-01

2,683 downloads per month

MIT/Apache

11KB
176 lines

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

Dependencies

~150KB