Class LegacyDirectWriter
- java.lang.Object
-
- org.apache.lucene.backward_codecs.packed.LegacyDirectWriter
-
public final class LegacyDirectWriter extends java.lang.Object
Class for writing packed integers to be directly read from Directory. Integers can be read on-the-fly viaLegacyDirectReader
.Unlike PackedInts, it optimizes for read i/o operations and supports > 2B values. Example usage:
int bitsPerValue = LegacyDirectWriter.bitsRequired(100); // values up to and including 100 IndexOutput output = dir.createOutput("packed", IOContext.DEFAULT); DirectWriter writer = LegacyDirectWriter.getInstance(output, numberOfValues, bitsPerValue); for (int i = 0; i < numberOfValues; i++) { writer.add(value); } writer.finish(); output.close();
- See Also:
LegacyDirectReader
-
-
Field Summary
Fields Modifier and Type Field Description (package private) int
bitsPerValue
(package private) long
count
(package private) PackedInts.Encoder
encoder
(package private) boolean
finished
(package private) int
iterations
(package private) byte[]
nextBlocks
(package private) long[]
nextValues
(package private) long
numValues
(package private) int
off
(package private) DataOutput
output
(package private) static int[]
SUPPORTED_BITS_PER_VALUE
-
Constructor Summary
Constructors Constructor Description LegacyDirectWriter(DataOutput output, long numValues, int bitsPerValue)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
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 int
computeIterations(PackedInts.Encoder encoder, int valueCount, int ramBudget)
void
finish()
finishes writingprivate void
flush()
static LegacyDirectWriter
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 Detail
-
bitsPerValue
final int bitsPerValue
-
numValues
final long numValues
-
output
final DataOutput output
-
count
long count
-
finished
boolean finished
-
off
int off
-
nextBlocks
final byte[] nextBlocks
-
nextValues
final long[] nextValues
-
encoder
final PackedInts.Encoder encoder
-
iterations
final int iterations
-
SUPPORTED_BITS_PER_VALUE
static final int[] SUPPORTED_BITS_PER_VALUE
-
-
Constructor Detail
-
LegacyDirectWriter
LegacyDirectWriter(DataOutput output, long numValues, int bitsPerValue)
-
-
Method Detail
-
computeIterations
private static int computeIterations(PackedInts.Encoder encoder, int valueCount, int ramBudget)
-
add
public void add(long l) throws java.io.IOException
Adds a value to this writer- Throws:
java.io.IOException
-
flush
private void flush() throws java.io.IOException
- Throws:
java.io.IOException
-
finish
public void finish() throws java.io.IOException
finishes writing- Throws:
java.io.IOException
-
getInstance
public static LegacyDirectWriter getInstance(DataOutput output, long numValues, int bitsPerValue)
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:
PackedInts.bitsRequired(long)
-
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:
PackedInts.unsignedBitsRequired(long)
-
-