Methods Summary |
---|
private static java.util.Hashtable | buildHuffman(int[] tlen)
int len = tlen.length;
int[] bl_count = new int[33];
int[] next_code = new int[33];
int maxlen = -1;
for (int i = 0; i < len; i++) {
if (tlen[i] > maxlen) {
maxlen = tlen[i];
}
++bl_count[tlen[i]];
}
int code = 0;
bl_count[0] = 0;
for (int bits = 1; bits <= maxlen; bits++) {
code = (code + bl_count[bits - 1]) << 1;
next_code[bits] = code;
}
Hashtable codeTable = new Hashtable(len);
for (int n = 0; n < len; n++) {
int l = tlen[n];
if (l != 0) {
codeTable.put(getKey(next_code[l], l), new Integer(n));
++next_code[l];
}
}
return codeTable;
|
private static java.lang.Integer | getKey(int code, int len)
return new Integer((code << 8) | len);
|
private int | getVal(int code, int len)
Object o = codeTable.get(getKey(code, len));
if (o != null) {
return ((Integer)o).intValue();
}
return -1;
|
public int | readSymbol()
int code = in.readHuffmanBits(minLen);
int len = minLen;
while (true) {
int val = getVal(code, len);
if (val != -1) {
return val;
}
code = (code << 1) | in.readBit();
++len;
}
|