org.at4j.support.comp
Class IntMoveToFront

java.lang.Object
  extended by org.at4j.support.comp.IntMoveToFront

public class IntMoveToFront
extends Object

A move-to-front (MTF) encoder and decoder for integers. For more information on MTF encoding, seethe Wikipedia article on move-to-front transforms.

This object is not thread safe. Clients must provide external synchronization if they are to use it from several concurrent threads.

Since:
1.1
Author:
Karl Gustafsson
See Also:
ByteMoveToFront

Constructor Summary
IntMoveToFront(int[] alphabet)
          Create a byte MTF encoder/decoder that transforms integers using the supplied initial alphabet.
IntMoveToFront(int minValue, int maxValue)
          Create a byte MTF encoder/decoder that transforms integers in the range between minValue and maxValue.
 
Method Summary
 int decode(int index)
          Decode a single integer and update the MTF alphabet.
 int[] decode(int[] in, int[] out)
          Decode an array of integers and update the MTF alphabet.
 int[] encode(int[] in, int[] out)
          Encode the integers in in and store them in the array out .
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IntMoveToFront

public IntMoveToFront(int minValue,
                      int maxValue)
               throws IndexOutOfBoundsException
Create a byte MTF encoder/decoder that transforms integers in the range between minValue and maxValue.

The initial alphabet of the transformer will be minValue … maxValue.

Parameters:
minValue - The start value of the range.
maxValue - The end value of the range.
Throws:
IndexOutOfBoundsException - If the min value is equal to or greater than the max value.

IntMoveToFront

public IntMoveToFront(int[] alphabet)
Create a byte MTF encoder/decoder that transforms integers using the supplied initial alphabet.

Parameters:
alphabet - The initial alphabet. This integer array is not copied by this method and it will be modified by encoding or decoding operations.
Method Detail

encode

public int[] encode(int[] in,
                    int[] out)
             throws ArrayIndexOutOfBoundsException,
                    IllegalArgumentException
Encode the integers in in and store them in the array out . The MTF alphabet is also updated by this method.

Parameters:
in - The integers to encode.
out - The array to store the encoded integers in. This array must be at least as long as in.
Returns:
out
Throws:
ArrayIndexOutOfBoundsException - If any of the integers in in are not in the MTF alphabet.
IllegalArgumentException - If the out array is too short.

decode

public int decode(int index)
Decode a single integer and update the MTF alphabet.

Parameters:
index - The index in the MTF alphabet for the integer.
Returns:
The integer.

decode

public int[] decode(int[] in,
                    int[] out)
             throws ArrayIndexOutOfBoundsException,
                    IllegalArgumentException
Decode an array of integers and update the MTF alphabet. The decoded integers are stored in out.

Parameters:
in - The integers to decode.
out - The array to store the decoded integers in. This array must be at least as long as in.
Returns:
out
Throws:
ArrayIndexOutOfBoundsException - If any of the integers in in are not in the MTF alphabet.
IllegalArgumentException - If out is too short.