Package org.terrier.compression.bit
Class BitInBase
- java.lang.Object
-
- org.terrier.compression.bit.BitInBase
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,BitIn
- Direct Known Subclasses:
BitFileBuffered.BitInBuffered
,BitInputStream
public abstract class BitInBase extends java.lang.Object implements BitIn
Base class for various BitIn implementations- Since:
- 3.6
- Author:
- Craig Macdonald
-
-
Field Summary
Fields Modifier and Type Field Description protected int
bitOffset
bit offset in this byte, and in the larger fileprotected byte
byteRead
current byteprotected long
offset
offset in the larger file-
Fields inherited from interface org.terrier.compression.bit.BitIn
USUAL_EXTENSION
-
-
Constructor Summary
Constructors Constructor Description BitInBase()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
align()
Aligns the stream to the next bytebyte
getBitOffset()
Returns the bit offset in the last byte.long
getByteOffset()
Returns the byte offset of the stream.protected abstract void
incrByte()
Move forward one byte.protected abstract void
incrByte(int i)
Move forward i bytes.int
readBinary(int len)
Reads a binary integer from the already read buffer.int
readDelta()
Reads a delta encoded integer from the underlying streamint
readGamma()
Reads a gamma encoded integer from the underlying streamint
readGolomb(int b)
Reads a Golomb encoded integerprotected void
readIn()
Reads a new byte from the InputStream if we have finished with the current one.void
readInterpolativeCoding(int[] data, int localoffset, int len, int lo, int hi)
Reads a sequence of numbers from the stream interpolative coded.int
readMinimalBinary(int b)
Reads a binary encoded integer, given an upper boundint
readMinimalBinaryZero(int b)
Reads a minimal binary encoded number, when the upper bound can b zero.int
readSkewedGolomb(int b)
Reads a skewed-golomb encoded integer from the underlying stream Consider a bucket-vectorv = <0, 2b, 4b, ...
int
readUnary()
Reads a unary encoded integer from the underlying streamvoid
skipBits(int len)
Skip a number of bits in the current input stream
-
-
-
Method Detail
-
getByteOffset
public 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. Use only when writting- Specified by:
getByteOffset
in interfaceBitIn
- Returns:
- the byte offset in the stream.
-
getBitOffset
public byte getBitOffset()
Returns the bit offset in the last byte. It corresponds to the position in which the next bit will be written. Use only when writting.- Specified by:
getBitOffset
in interfaceBitIn
- Returns:
- the bit offset in the stream.
-
readUnary
public int readUnary() throws java.io.IOException
Reads a unary encoded integer from the underlying stream
-
readBinary
public int readBinary(int len) throws java.io.IOException
Reads a binary integer from the already read buffer.- Specified by:
readBinary
in interfaceBitIn
- Parameters:
len
- the number of binary bits to read- Returns:
- the decoded integer
- Throws:
java.io.IOException
- if an I/O error occurs
-
readDelta
public int readDelta() throws java.io.IOException
Reads a delta encoded integer from the underlying stream
-
readGamma
public int readGamma() throws java.io.IOException
Reads a gamma encoded integer from the underlying stream
-
readSkewedGolomb
public int readSkewedGolomb(int b) throws java.io.IOException
Reads a skewed-golomb encoded integer from the underlying stream Consider a bucket-vectorv = <0, 2b, 4b, ... , 2^i b, ...>
The sum of the elements in the vector goesb, 3b, 7b, 2^(i-1)*b
- Specified by:
readSkewedGolomb
in interfaceBitIn
- Returns:
- the number read
- Throws:
java.io.IOException
- if an I/O error occurs
-
readGolomb
public int readGolomb(int b) throws java.io.IOException
Reads a Golomb encoded integer- Specified by:
readGolomb
in interfaceBitIn
- Parameters:
b
- the golomb modulus- Returns:
- the int read
- Throws:
java.io.IOException
- if and I/O error occurs
-
readMinimalBinary
public int readMinimalBinary(int b) throws java.io.IOException
Reads a binary encoded integer, given an upper bound- Specified by:
readMinimalBinary
in interfaceBitIn
- Parameters:
b
- the upper bound- Returns:
- the int read
- Throws:
java.io.IOException
- if an I/O error occurs
-
readMinimalBinaryZero
public int readMinimalBinaryZero(int b) throws java.io.IOException
Reads a minimal binary encoded number, when the upper bound can b zero. Used to interpolative code- Specified by:
readMinimalBinaryZero
in interfaceBitIn
- Parameters:
b
- the upper bound- Returns:
- the int read
- Throws:
java.io.IOException
- if an I/O error occurs
-
readInterpolativeCoding
public void readInterpolativeCoding(int[] data, int localoffset, int len, int lo, int hi) throws java.io.IOException
Reads a sequence of numbers from the stream interpolative coded.- Specified by:
readInterpolativeCoding
in interfaceBitIn
- Parameters:
data
- the result vectorlocaloffset
- offset where to write in the vectorlen
- the number of integers to decode.lo
- a lower bound (the same one passed to writeInterpolativeCoding)hi
- an upper bound (the same one passed to writeInterpolativeCoding)- Throws:
java.io.IOException
- if an I/O error occurs
-
skipBits
public void skipBits(int len) throws java.io.IOException
Skip a number of bits in the current input stream
-
align
public void align() throws java.io.IOException
Aligns the stream to the next byte
-
incrByte
protected abstract void incrByte() throws java.io.IOException
Move forward one byte. The newly read byte should appear in the byteRead variable.- Throws:
java.io.IOException
-
incrByte
protected abstract void incrByte(int i) throws java.io.IOException
Move forward i bytes. The newly read byte should appear in byteRead variable.- Throws:
java.io.IOException
-
readIn
protected void readIn() throws java.io.IOException
Reads a new byte from the InputStream if we have finished with the current one.- Throws:
java.io.IOException
-
-