Skip to main content

encode_deltas

Function encode_deltas 

Source
pub fn encode_deltas(samples: &[i64]) -> Vec<u8> 
Expand description

Encodes a batch of integer samples as a starting value plus variable-length deltas.

§Arguments

  • samples - the integers to encode, in order.

§Returns

The compact encoding. A slowly changing series is far smaller than the eight bytes per sample a raw encoding would use.

§Examples

use pamoja_codec::{decode_deltas, encode_deltas};

let samples = [1000, 1001, 1003, 1002];
let bytes = encode_deltas(&samples);
assert!(bytes.len() < samples.len() * 8); // far smaller than eight bytes each
assert_eq!(decode_deltas(&bytes).unwrap(), samples);