|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectpt.tumba.ngram.compression.ArithEncoder
public final class ArithEncoder
Performs arithmetic encoding, converting cumulative probability
interval input into bit output. Cumulative probability intervals
are given as integer counts low, high and
total, with the range being
[low/total,high/total).
ArithDecoder,
BitOutput| Field Summary | |
|---|---|
private int |
_bitsToFollow
Number of bits beyond first bit that were normalized. |
protected long |
_high
The high bound on the current interval for coding. |
protected long |
_low
The low bound on the current interval for coding. |
private BitOutput |
_out
Bit output stream for writing encoding bits. |
protected static int |
CODE_VALUE_BITS
Precision of coding, expressed in number of bits used for arithmetic before shifting out partial results. |
protected static long |
FIRST_QUARTER
1/4 of the largest possible value plus one. |
protected static long |
HALF
1/2 of the largest possible value; 2 * FIRST_QUARTER |
protected static long |
THIRD_QUARTER
3/4 of the largest possible value; 3 * FIRST_QUARTER |
protected static long |
TOP_VALUE
The largest possible interval value. |
| Constructor Summary | |
|---|---|
ArithEncoder(BitOutput out)
Construct an arithmetic coder from a bit output. |
|
ArithEncoder(java.io.OutputStream out)
Construct an arithmetic coder from an output stream. |
|
| Method Summary | |
|---|---|
private void |
bitPlusFollowFalse()
Write a false bit, and then a number of true bits
equal to the number of bits to follow. |
private void |
bitPlusFollowTrue()
Write a true bit, and then a number of false bits
equal to the number of bits to follow. |
void |
close()
Close the arithmetic encoder, writing all bits that are buffered and closing the underlying output streams. |
void |
encode(int[] counts)
Encodes an interval expressed as a low count, high count and total count in an array {low,high,total}. |
void |
encode(int lowCount,
int highCount,
int totalCount)
Encodes an interval expressed as a low count, high count and total count. |
void |
flush()
Flushes bit output. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected long _low
protected long _high
protected static final int CODE_VALUE_BITS
protected static final long TOP_VALUE
1s.
protected static final long FIRST_QUARTER
protected static final long HALF
2 * FIRST_QUARTER
protected static final long THIRD_QUARTER
3 * FIRST_QUARTER
private final BitOutput _out
private int _bitsToFollow
| Constructor Detail |
|---|
public ArithEncoder(BitOutput out)
out - Underlying bit output.public ArithEncoder(java.io.OutputStream out)
out - Underlying output stream.| Method Detail |
|---|
public void close()
throws java.io.IOException
java.io.IOException - If there is an exception writing to or closing the underlying output stream.
public void flush()
throws java.io.IOException
java.io.IOException - If there is an exception flushing the underlying output stream.
public void encode(int[] counts)
throws java.io.IOException
{low,high,total}.
counts - Low, high and total counts of symbols.
java.io.IOException - If there is an exception writing to the underlying stream.encode(int,int,int)
public void encode(int lowCount,
int highCount,
int totalCount)
throws java.io.IOException
highCount - lowCount + 1.
lowCount - Cumulative count of symbols below current one.highCount - Cumulative count of symbols below current one plus currnet one.totalCount - Cumulative count of all symbols.
java.io.IOException - If there is an exception writing to the underlying stream.encode(int[])
private void bitPlusFollowTrue()
throws java.io.IOException
true bit, and then a number of false bits
equal to the number of bits to follow.
java.io.IOException - If there is an exception writing a bit.
private void bitPlusFollowFalse()
throws java.io.IOException
false bit, and then a number of true bits
equal to the number of bits to follow.
java.io.IOException - If there is an exception writing a bit.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||