Package org.apache.lucene.util.fst
Class BitTableUtil
- java.lang.Object
-
- org.apache.lucene.util.fst.BitTableUtil
-
class BitTableUtil extends java.lang.Object
Static helper methods forFST.Arc.BitTable
.
-
-
Constructor Summary
Constructors Constructor Description BitTableUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description (package private) static int
countBits(int bitTableBytes, FST.BytesReader reader)
Counts all bits set in the bit-table.(package private) static int
countBitsUpTo(int bitIndex, FST.BytesReader reader)
Counts the bits set up to the given bit zero-based index, exclusive.(package private) static boolean
isBitSet(int bitIndex, FST.BytesReader reader)
Returns whether the bit at given zero-based index is set.(package private) static int
nextBitSet(int bitIndex, int bitTableBytes, FST.BytesReader reader)
Returns the index of the next bit set following the given bit zero-based index.(package private) static int
previousBitSet(int bitIndex, FST.BytesReader reader)
Returns the index of the previous bit set preceding the given bit zero-based index.private static long
read8Bytes(FST.BytesReader reader)
private static long
readByte(FST.BytesReader reader)
private static long
readUpTo8Bytes(int numBytes, FST.BytesReader reader)
-
-
-
Method Detail
-
isBitSet
static boolean isBitSet(int bitIndex, FST.BytesReader reader) throws java.io.IOException
Returns whether the bit at given zero-based index is set.
Example: bitIndex 10 means the third bit on the right of the second byte.- Parameters:
bitIndex
- The bit zero-based index. It must be greater than or equal to 0, and strictly less thannumber of bit-table bytes * Byte.SIZE
.reader
- TheFST.BytesReader
to read. It must be positioned at the beginning of the bit-table.- Throws:
java.io.IOException
-
countBits
static int countBits(int bitTableBytes, FST.BytesReader reader) throws java.io.IOException
Counts all bits set in the bit-table.- Parameters:
bitTableBytes
- The number of bytes in the bit-table.reader
- TheFST.BytesReader
to read. It must be positioned at the beginning of the bit-table.- Throws:
java.io.IOException
-
countBitsUpTo
static int countBitsUpTo(int bitIndex, FST.BytesReader reader) throws java.io.IOException
Counts the bits set up to the given bit zero-based index, exclusive.
In other words, how many 1s there are up to the bit at the given index excluded.
Example: bitIndex 10 means the third bit on the right of the second byte.- Parameters:
bitIndex
- The bit zero-based index, exclusive. It must be greater than or equal to 0, and less than or equal tonumber of bit-table bytes * Byte.SIZE
.reader
- TheFST.BytesReader
to read. It must be positioned at the beginning of the bit-table.- Throws:
java.io.IOException
-
nextBitSet
static int nextBitSet(int bitIndex, int bitTableBytes, FST.BytesReader reader) throws java.io.IOException
Returns the index of the next bit set following the given bit zero-based index.
For example with bits 100011: the next bit set after index=-1 is at index=0; the next bit set after index=0 is at index=1; the next bit set after index=1 is at index=5; there is no next bit set after index=5.- Parameters:
bitIndex
- The bit zero-based index. It must be greater than or equal to -1, and strictly less thannumber of bit-table bytes * Byte.SIZE
.bitTableBytes
- The number of bytes in the bit-table.reader
- TheFST.BytesReader
to read. It must be positioned at the beginning of the bit-table.- Returns:
- The zero-based index of the next bit set after the provided
bitIndex
; or -1 if none. - Throws:
java.io.IOException
-
previousBitSet
static int previousBitSet(int bitIndex, FST.BytesReader reader) throws java.io.IOException
Returns the index of the previous bit set preceding the given bit zero-based index.
For example with bits 100011: there is no previous bit set before index=0. the previous bit set before index=1 is at index=0; the previous bit set before index=5 is at index=1; the previous bit set before index=64 is at index=5;- Parameters:
bitIndex
- The bit zero-based index. It must be greater than or equal to 0, and less than or equal tonumber of bit-table bytes * Byte.SIZE
.reader
- TheFST.BytesReader
to read. It must be positioned at the beginning of the bit-table.- Returns:
- The zero-based index of the previous bit set before the provided
bitIndex
; or -1 if none. - Throws:
java.io.IOException
-
readByte
private static long readByte(FST.BytesReader reader) throws java.io.IOException
- Throws:
java.io.IOException
-
readUpTo8Bytes
private static long readUpTo8Bytes(int numBytes, FST.BytesReader reader) throws java.io.IOException
- Throws:
java.io.IOException
-
read8Bytes
private static long read8Bytes(FST.BytesReader reader) throws java.io.IOException
- Throws:
java.io.IOException
-
-