Struct rdir_encoding::RunLength
[−]
[src]
pub struct RunLength;
Run-length encoding.
Run-length decoding can generally be used to compress arrays that contain stretches of equal values. Instead of storing each value itself, stretches of equal values are represented by the value itself and the occurrence count, that is a value/count pair.
Examples
use rdir_encoding::RunLength; let data = [1, 1, 1, 1, 2, 1, 1, 1, 1]; let encoded = RunLength::encode(&data).unwrap(); assert_eq!(vec![1, 4, 2, 1, 1, 4], encoded); let decoded = RunLength::decode(&encoded).unwrap(); assert_eq!(vec![1, 1, 1, 1, 2, 1, 1, 1, 1], decoded);
Methods
impl RunLength
[src]
pub fn decode<T>(values: &[T]) -> Result<Vec<i32>, RdirError> where
T: Integer + NumCast + PrimInt,
[src]
T: Integer + NumCast + PrimInt,
pub fn encode<T>(values: &[T]) -> Result<Vec<i32>, RdirError> where
T: Integer + NumCast + PrimInt,
[src]
T: Integer + NumCast + PrimInt,
Encode any array of 'T' where T
can be any Integer.