Function encode_move_to_front

Source
pub fn encode_move_to_front<T: Eq + Clone>(
    input: &[T],
    ordering: &mut Vec<T>,
) -> Vec<usize>
Expand description

Encodes a sequence of elements using the Move-to-Front (MTF) algorithm.

§Arguments

  • input: A slice of elements to be encoded.
  • ordering: A mutable reference to a vector representing the current ordering of elements.

§Returns

A vector of indices representing the encoded elements.

§Example

use generic_compression::encode_move_to_front;
let input = vec!['h', 'e', 'l', 'l', 'o'];
let mut ordering = vec!['e', 'h', 'l', 'o'];
let encoded = encode_move_to_front(&input, &mut ordering);
assert_eq!(encoded, vec![1, 1, 2, 0, 3]);