Struct rdir_encoding::RecursiveIndexing
[−]
[src]
pub struct RecursiveIndexing;
Recursive indexing encoding Recursive indexing encodes values such that the encoded values lie within the open interval (MIN, MAX). This allows to create a more compact representation of a 32-bit signed integer array when the majority of values in the array fit into 16-bit (or 8-bit). To encode each value in the input array the method stores the value itself if it lies within the open interval (MIN, MAX), otherwise the MAX (or MIN if the number is negative) interval endpoint is stored and subtracted from the input value. This process of storing and subtracting is repeated recursively until the remainder lies within the interval.
Note that MAX
and MIN
are the largest and smallest value that can be
represented by the i16
integer type
Examples
use rdir_encoding::RecursiveIndexing; let data = [1, 420, 32767, 120, -32768, 32769]; let encoded = RecursiveIndexing::encode(&data).unwrap(); assert_eq!(encoded, vec![1, 420, 32767, 0, 120, -32768, 0, 32767, 2]); let decoded = RecursiveIndexing::decode(&encoded).unwrap(); assert_eq!(decoded, data);
Methods
impl RecursiveIndexing
[src]
pub fn decode<T>(values: &[T]) -> Result<Vec<i32>, RdirError> where
T: Integer + NumCast + PrimInt,
[src]
T: Integer + NumCast + PrimInt,
Decode and return the decoded data
pub fn encode(values: &[i32]) -> Result<Vec<i16>, RdirError>
[src]
Encode values