Skip to content

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

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

nyurik/delta-encoding

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

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

Topics

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Packages

No packages published