1 package SevenZip.Compression.RangeCoder;
2 import java.io.IOException;
4 public class BitTreeEncoder
9 public BitTreeEncoder(int numBitLevels)
11 NumBitLevels = numBitLevels;
12 Models = new short[1 << numBitLevels];
17 Decoder.InitBitModels(Models);
20 public void Encode(Encoder rangeEncoder, int symbol) throws IOException
23 for (int bitIndex = NumBitLevels; bitIndex != 0; )
26 int bit = (symbol >>> bitIndex) & 1;
27 rangeEncoder.Encode(Models, m, bit);
32 public void ReverseEncode(Encoder rangeEncoder, int symbol) throws IOException
35 for (int i = 0; i < NumBitLevels; i++)
38 rangeEncoder.Encode(Models, m, bit);
44 public int GetPrice(int symbol)
48 for (int bitIndex = NumBitLevels; bitIndex != 0; )
51 int bit = (symbol >>> bitIndex) & 1;
52 price += Encoder.GetPrice(Models[m], bit);
58 public int ReverseGetPrice(int symbol)
62 for (int i = NumBitLevels; i != 0; i--)
66 price += Encoder.GetPrice(Models[m], bit);
72 public static int ReverseGetPrice(short[] Models, int startIndex,
73 int NumBitLevels, int symbol)
77 for (int i = NumBitLevels; i != 0; i--)
81 price += Encoder.GetPrice(Models[startIndex + m], bit);
87 public static void ReverseEncode(short[] Models, int startIndex,
88 Encoder rangeEncoder, int NumBitLevels, int symbol) throws IOException
91 for (int i = 0; i < NumBitLevels; i++)
94 rangeEncoder.Encode(Models, startIndex + m, bit);