# Class Utils

java.lang.Object
htsjdk.samtools.cram.compression.rans.Utils

public final class Utils extends Object
Utility methods for rANS encoding and decoding: cumulative frequency lookup, state renormalization, and frequency table normalization.

## Constructor Summary

Constructors
Constructor
Description
`Utils()`

## Method Summary

Modifier and Type
Method
Description
`static void`
`normaliseFrequenciesOrder0(int[] F, int bits)`
Normalize symbol frequencies so they sum to `1 << bits`.
`static void`
`normaliseFrequenciesOrder0Shift(int[] frequencies, int bits)`
Shift-based frequency normalization: scale frequencies by a power of 2 so they sum to `1 << bits`.
`static void`
`normaliseFrequenciesOrder1(int[][] F, int shift)`
Normalize Order-1 frequency tables: for each context symbol with non-zero frequency, compute the minimum bit size and normalize that context's frequency table.
`static void`
`normaliseFrequenciesOrder1Shift(int[][] F, int shift)`
Shift-based normalization for all Order-1 context rows.
`static long`
`RANSDecodeRenormalize4x8(long r, byte[] buf, int[] posHolder)`
4x8 renormalization: reads 1 byte at a time from buf at posHolder[0] until state reaches lower bound.
`static long`
`RANSDecodeRenormalizeNx16(long r, byte[] buf, int[] posHolder)`
Nx16 renormalization: reads 2 LE bytes from buf at posHolder[0] if state is below lower bound.
`static int`
`RANSGetCumulativeFrequency(long r, int scaleBits)`
Extract the cumulative frequency from a rANS state by masking off the lower `scaleBits` bits.

### Methods inherited from class Object

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

## Constructor Details

### Utils

public Utils()

## Method Details

### RANSGetCumulativeFrequency

public static int RANSGetCumulativeFrequency(long r, int scaleBits)
Extract the cumulative frequency from a rANS state by masking off the lower `scaleBits` bits.

Parameters:
  `r` - the current rANS state
  `scaleBits` - log2 of the total frequency sum
Returns:
  the cumulative frequency used to look up the decoded symbol

### RANSDecodeRenormalizeNx16

public static long RANSDecodeRenormalizeNx16(long r, byte[] buf, int[] posHolder)
Nx16 renormalization: reads 2 LE bytes from buf at posHolder[0] if state is below lower bound.

### RANSDecodeRenormalize4x8

public static long RANSDecodeRenormalize4x8(long r, byte[] buf, int[] posHolder)
4x8 renormalization: reads 1 byte at a time from buf at posHolder[0] until state reaches lower bound.

### normaliseFrequenciesOrder0

public static void normaliseFrequenciesOrder0(int[] F, int bits)
Normalize symbol frequencies so they sum to `1 << bits`. Uses fixed-point arithmetic to scale frequencies proportionally.

### normaliseFrequenciesOrder1

public static void normaliseFrequenciesOrder1(int[][] F, int shift)
Normalize Order-1 frequency tables: for each context symbol with non-zero frequency, compute the minimum bit size and normalize that context's frequency table.

### normaliseFrequenciesOrder0Shift

public static void normaliseFrequenciesOrder0Shift(int[] frequencies, int bits)
Shift-based frequency normalization: scale frequencies by a power of 2 so they sum to `1 << bits`.

### normaliseFrequenciesOrder1Shift

public static void normaliseFrequenciesOrder1Shift(int[][] F, int shift)
Shift-based normalization for all Order-1 context rows.