Class LegacyDirectWriter
- java.lang.Object
-
- org.apache.lucene.backward_codecs.packed.LegacyDirectWriter
-
public final class LegacyDirectWriter extends 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
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(long l)Adds a value to this writerstatic intbitsRequired(long maxValue)Returns how many bits are required to hold values up to and including maxValuevoidfinish()finishes writingstatic LegacyDirectWritergetInstance(DataOutput output, long numValues, int bitsPerValue)Returns an instance suitable for encodingnumValuesusingbitsPerValuestatic intunsignedBitsRequired(long maxValue)Returns how many bits are required to hold values up to and including maxValue, interpreted as an unsigned value.
-
-
-
Method Detail
-
add
public void add(long l) throws IOExceptionAdds a value to this writer- Throws:
IOException
-
finish
public void finish() throws IOExceptionfinishes writing- Throws:
IOException
-
getInstance
public static LegacyDirectWriter getInstance(DataOutput output, long numValues, int bitsPerValue)
Returns an instance suitable for encodingnumValuesusingbitsPerValue
-
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)
-
-