org.h2.dev.util

## Class AnsCompression

- java.lang.Object
- - org.h2.dev.util.AnsCompression

    public class AnsCompression
    extends java.lang.Object

An ANS (Asymmetric Numeral Systems) compression tool. It uses the range variant.

### Method Summary

Methods
`static void` `countFrequencies(int[] freq, byte[] data)` Count the frequencies of codes in the data, and increment the target frequency table.
`static byte[]` `decode(int[] freq, byte[] data, int length)` Decode the data.
`static byte[]` `encode(int[] freq, byte[] data)` Encode the data.
`static void` `scaleFrequencies(int[] freq, int total)` Scale the frequencies to a new total.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Method Detail

#### countFrequencies

    public static void countFrequencies(int[] freq,
                        byte[] data)

Count the frequencies of codes in the data, and increment the target frequency table.

Parameters:
  `freq` - the target frequency table
  `data` - the data

#### scaleFrequencies

    public static void scaleFrequencies(int[] freq,
                        int total)

Scale the frequencies to a new total. Frequencies of 0 are kept as 0; larger frequencies result in at least 1.

Parameters:
  `freq` - the (source and target) frequency table
  `total` - the target total (sum of all frequencies)

#### encode

    public static byte[] encode(int[] freq,
                byte[] data)

Encode the data.

Parameters:
  `freq` - the frequency table (will be scaled)
  `data` - the source data (uncompressed)
Returns:
  the compressed data

#### decode

    public static byte[] decode(int[] freq,
                byte[] data,
                int length)

Decode the data.

Parameters:
  `freq` - the frequency table (will be scaled)
  `data` - the compressed data
  `length` - the target length
Returns:
  the uncompressed result