Package org.terrier.compression.bit
Interface BitOut
-
- All Superinterfaces:
java.lang.AutoCloseable
,java.io.Closeable
- All Known Implementing Classes:
BitByteOutputStream
,BitOutputStream
,MemorySBOS
public interface BitOut extends java.io.Closeable
Interface describing the writing compression methods supported by the BitOutputStream classes. Integers written through these compression methods must be greater than 0.- Since:
- 2.0
- Author:
- Craig Macdonald
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description byte
getBitOffset()
Returns the bit offset in the last byte.long
getByteOffset()
Returns the byte offset of the stream.int
writeBinary(int len, int x)
Writes an integer in binary format to the stream.int
writeDelta(int x)
Writes an integer x into the stream using delta encoding.int
writeGamma(int x)
Writes an integer x into the stream using gamma encoding.int
writeGolomb(int x, int b)
Writes and integer x into the stream using golomb coding.int
writeInt(int x, int len)
Writes an integer x into the underlying OutputStream.int
writeInterpolativeCode(int[] data, int offset, int len, int lo, int hi)
Writes a sequence of integers using interpolative coding.int
writeMinimalBinary(int x, int b)
Writes an integer x using minimal binary encoding, given an upper bound.int
writeSkewedGolomb(int x, int b)
Writes and integer x into the stream using skewed-golomb coding.int
writeUnary(int x)
Writes an integer x using unary encoding.
-
-
-
Method Detail
-
getByteOffset
long getByteOffset()
Returns the byte offset of the stream. It corresponds to the position of the byte in which the next bit will be written.- Returns:
- the byte offset in the stream.
-
getBitOffset
byte getBitOffset()
Returns the bit offset in the last byte. It corresponds to the position in which the next bit will be written.- Returns:
- the bit offset in the stream.
-
writeUnary
int writeUnary(int x) throws java.io.IOException
Writes an integer x using unary encoding. The encoding is a sequence of x -1 zeros and 1 one: 1, 01, 001, 0001, etc .. This method is not failsafe, it doesn't check if the argument is 0 or negative.- Parameters:
x
- the number to write- Returns:
- the number of bits written
- Throws:
java.io.IOException
- if an I/O error occurs.
-
writeGamma
int writeGamma(int x) throws java.io.IOException
Writes an integer x into the stream using gamma encoding. This method is not failsafe, it doesn't check if the argument is 0 or negative.- Parameters:
x
- the int number to write- Returns:
- the number of bits written
- Throws:
java.io.IOException
- if an I/O error occurs.
-
writeBinary
int writeBinary(int len, int x) throws java.io.IOException
Writes an integer in binary format to the stream.- Parameters:
len
- size in bits of the number.x
- the integer to write.- Returns:
- the number of bits written.
- Throws:
java.io.IOException
- if an I/O error occurs.
-
writeInterpolativeCode
int writeInterpolativeCode(int[] data, int offset, int len, int lo, int hi) throws java.io.IOException
Writes a sequence of integers using interpolative coding. The data must be sorted (increasing order).- Parameters:
data
- the vector containing the integer sequence.offset
- the offset intodata
where the sequence starts.len
- the number of integers to code.lo
- a lower bound (must be smaller than or equal to the first integer in the sequence).hi
- an upper bound (must be greater than or equal to the last integer in the sequence).- Returns:
- the number of written bits.
- Throws:
java.io.IOException
- if an I/O error occurs.
-
writeSkewedGolomb
int writeSkewedGolomb(int x, int b) throws java.io.IOException
Writes and integer x into the stream using skewed-golomb coding. Consider a bucket-vectorv = <b, 2b, 4b, ... , 2^i b, ...>
an integerx
is coded asunary(k+1)
wherek
is the indexsum(i=0)(k) v_i > x <= sum(i=0)(k+1)
, sok = log(x/b + 1)
sum_i = b(2^n -1)
(geometric progression) and the remainder withlog(v_k)
bits in binary iflower = ceil(x/b) -> lower = 2^i * b -> i = log(ceil(x/b)) + 1
the remainderx - sum_i 2^i*b - 1 = x - b(2^n - 1) - 1
is coded withfloor(log(v_k))
bits This method is not failsafe, it doesn't check if the argument or the modulus is 0 or negative.- Parameters:
x
- the number to writeb
- the parameter for golomb coding- Returns:
- the number of bits written
- Throws:
java.io.IOException
- if and I/O error occurs
-
writeGolomb
int writeGolomb(int x, int b) throws java.io.IOException
Writes and integer x into the stream using golomb coding. This method is not failsafe, it doesn't check if the argument or the modulus is 0 or negative.- Parameters:
x
- the number to writeb
- the parameter for golomb coding- Returns:
- the number of bits written
- Throws:
java.io.IOException
- if and I/O error occurs
-
writeMinimalBinary
int writeMinimalBinary(int x, int b) throws java.io.IOException
Writes an integer x using minimal binary encoding, given an upper bound. This method is not failsafe, it doesn't check if the argument is 0 or negative.- Parameters:
x
- the number to writeb
- and strict bound forx
- Returns:
- the number of bits written
- Throws:
java.io.IOException
- if an I/O error occurs.
-
writeDelta
int writeDelta(int x) throws java.io.IOException
Writes an integer x into the stream using delta encoding. This method is not failsafe, it doesn't check if the argument is 0 or negative.- Parameters:
x
- the int number to write- Returns:
- the number of bits written
- Throws:
java.io.IOException
- if an I/O error occurs.
-
writeInt
int writeInt(int x, int len) throws java.io.IOException
Writes an integer x into the underlying OutputStream. First, it checks if it fits into the current byte we are using for writing, and then it writes as many bytes as necessary- Parameters:
x
- the int to writelen
- length of the int in bits- Returns:
- the number of bits written
- Throws:
java.io.IOException
- if an I/O error occurs.
-
-