Package org.apache.lucene.util.packed
Class DirectWriter
java.lang.Object
org.apache.lucene.util.packed.DirectWriter
Class for writing packed integers to be directly read from Directory. Integers can be read
on-the-fly via
DirectReader
.
Unlike PackedInts, it optimizes for read i/o operations and supports > 2B values. Example usage:
int bitsPerValue = DirectWriter.bitsRequired(100); // values up to and including 100 IndexOutput output = dir.createOutput("packed", IOContext.DEFAULT); DirectWriter writer = DirectWriter.getInstance(output, numberOfValues, bitsPerValue); for (int i = 0; i < numberOfValues; i++) { writer.add(value); } writer.finish(); output.close();
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) final int
(package private) long
(package private) boolean
(package private) final byte[]
(package private) final long[]
(package private) final long
(package private) int
(package private) final DataOutput
(package private) static final int[]
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(long l) Adds a value to this writerstatic int
bitsRequired
(long maxValue) Returns how many bits are required to hold values up to and including maxValueprivate static void
encode
(long[] nextValues, int upTo, byte[] nextBlocks, int bitsPerValue) void
finish()
finishes writingprivate void
flush()
static DirectWriter
getInstance
(DataOutput output, long numValues, int bitsPerValue) Returns an instance suitable for encodingnumValues
usingbitsPerValue
private static int
roundBits
(int bitsRequired) Round a number of bits per value to the next amount of bits per value that is supported by this writer.static int
unsignedBitsRequired
(long maxValue) Returns how many bits are required to hold values up to and including maxValue, interpreted as an unsigned value.
-
Field Details
-
bitsPerValue
final int bitsPerValue -
numValues
final long numValues -
output
-
count
long count -
finished
boolean finished -
off
int off -
nextBlocks
final byte[] nextBlocks -
nextValues
final long[] nextValues -
SUPPORTED_BITS_PER_VALUE
static final int[] SUPPORTED_BITS_PER_VALUE
-
-
Constructor Details
-
DirectWriter
DirectWriter(DataOutput output, long numValues, int bitsPerValue)
-
-
Method Details
-
add
Adds a value to this writer- Throws:
IOException
-
flush
- Throws:
IOException
-
encode
private static void encode(long[] nextValues, int upTo, byte[] nextBlocks, int bitsPerValue) -
finish
finishes writing- Throws:
IOException
-
getInstance
Returns an instance suitable for encodingnumValues
usingbitsPerValue
-
roundBits
private static int roundBits(int bitsRequired) Round a number of bits per value to the next amount of bits per value that is supported by this writer.- Parameters:
bitsRequired
- the amount of bits required- Returns:
- the next number of bits per value that is gte the provided value and supported by this writer
-
bitsRequired
public static int bitsRequired(long maxValue) Returns how many bits are required to hold values up to and including maxValue- Parameters:
maxValue
- the maximum value that should be representable.- Returns:
- the amount of bits needed to represent values from 0 to maxValue.
- See Also:
-
unsignedBitsRequired
public static int unsignedBitsRequired(long maxValue) Returns how many bits are required to hold values up to and including maxValue, interpreted as an unsigned value.- Parameters:
maxValue
- the maximum value that should be representable.- Returns:
- the amount of bits needed to represent values from 0 to maxValue.
- See Also:
-