https://github.com/nyurik/delta-encoding
A Rust library to encode and decode a delta-encoded stream of numbers
https://github.com/nyurik/delta-encoding
decoding-library delta-encoding encoding-library rust-library
Last synced: 7 months ago
JSON representation
A Rust library to encode and decode a delta-encoded stream of numbers
- Host: GitHub
- URL: https://github.com/nyurik/delta-encoding
- Owner: nyurik
- License: apache-2.0
- Created: 2022-06-29T23:19:59.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2025-06-11T18:02:46.000Z (8 months ago)
- Last Synced: 2025-06-18T23:17:08.321Z (7 months ago)
- Topics: decoding-library, delta-encoding, encoding-library, rust-library
- Language: Rust
- Homepage:
- Size: 67.4 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# Delta-Encoding library
[](https://github.com/nyurik/delta-encoding)
[](https://crates.io/crates/delta-encoding)
[](https://docs.rs/delta-encoding)
[](https://github.com/nyurik/delta-encoding/blob/main/LICENSE-APACHE)
[](https://github.com/nyurik/delta-encoding/actions)
[](https://app.codecov.io/gh/nyurik/delta-encoding)
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:
```text
1, 3, 2, 4, 5
```
the delta-encoded stream would be:
```text
1, 2, -1, 2, 1
```
## Usage
```rust
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 = data.iter().copied().deltas().collect();
assert_eq!(encoded, vec![1, 1, 3, -1, -2]);
// Consume and delta-encode
let encoded: Vec = 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 = data.iter().copied().original().collect();
assert_eq!(decoded, vec![1, 2, 5, 4, 2]);
// Consume and delta-decode
let decoded: Vec = data.into_iter().original().collect();
assert_eq!(decoded, vec![1, 2, 5, 4, 2]);
}
```
## Development
* This project is easier to develop with [just](https://github.com/casey/just#readme), 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
* Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or )
* MIT license ([LICENSE-MIT](LICENSE-MIT) or )
at your option.
### 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.