#encoder #codec #decoder #protobuf

delta-encoding

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

6 releases (3 breaking)

0.4.2 Dec 26, 2024
0.4.1 Dec 26, 2024
0.4.0 Jul 3, 2022
0.3.0 Jun 30, 2022
0.1.0 Jun 30, 2022

#280 in Encoding

Download history 453/week @ 2024-09-26 321/week @ 2024-10-03 557/week @ 2024-10-10 624/week @ 2024-10-17 693/week @ 2024-10-24 740/week @ 2024-10-31 517/week @ 2024-11-07 770/week @ 2024-11-14 432/week @ 2024-11-21 523/week @ 2024-11-28 767/week @ 2024-12-05 913/week @ 2024-12-12 561/week @ 2024-12-19 900/week @ 2024-12-26 4009/week @ 2025-01-02 2542/week @ 2025-01-09

8,075 downloads per month

MIT/Apache

15KB
253 lines

Delta-Encoding library

GitHub crates.io version docs.rs crates.io license CI build

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

  • This project is easier to develop with just, a modern alternative to make. Install it with cargo install just.
  • To get a list of available commands, run just.
  • To run tests, use just test.

License

Licensed under either of

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~150KB