Class GrowableWriter


public class GrowableWriter extends PackedInts.Mutable
Implements PackedInts.Mutable, but grows the bit count of the underlying packed ints on-demand.

Beware that this class will accept to set negative values but in order to do this, it will grow the number of bits per value to 64.

@lucene.internal

  • Field Summary

    Fields inherited from class org.apache.lucene.index.NumericDocValues

    EMPTY
  • Constructor Summary

    Constructors
    Constructor
    Description
    GrowableWriter(int startBitsPerValue, int valueCount, float acceptableOverheadRatio)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Sets all values to 0.
    void
    fill(int fromIndex, int toIndex, long val)
    Fill the mutable from fromIndex (inclusive) to toIndex (exclusive) with val.
    long
    get(int index)
    Returns the numeric value for the specified document ID.
    int
    get(int index, long[] arr, int off, int len)
    Bulk get: read at least one and at most len longs starting from index into arr[off:off+len] and return the actual number of values that have been read.
    Expert: if the bit-width of this reader matches one of java's native types, returns the underlying array (ie, byte[], short[], int[], long[]); else, returns null.
    int
     
     
    boolean
    Returns true if this implementation is backed by a native java array.
    long
    Return the in-memory size in bytes.
    resize(int newSize)
     
    void
    Save this mutable into out.
    void
    set(int index, long value)
    Set the value at the given index in the array.
    int
    set(int index, long[] arr, int off, int len)
    Bulk set: set at least one and at most len longs starting at off in arr into this mutable, starting at index.
    int
     

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • GrowableWriter

      public GrowableWriter(int startBitsPerValue, int valueCount, float acceptableOverheadRatio)
      Parameters:
      startBitsPerValue - the initial number of bits per value, may grow depending on the data
      valueCount - the number of values
      acceptableOverheadRatio - an acceptable overhead ratio
  • Method Details

    • get

      public long get(int index)
      Description copied from class: NumericDocValues
      Returns the numeric value for the specified document ID.
      Specified by:
      get in class NumericDocValues
      Parameters:
      index - document ID to lookup
      Returns:
      numeric value
    • size

      public int size()
      Specified by:
      size in class PackedInts.Reader
      Returns:
      the number of values.
    • getBitsPerValue

      public int getBitsPerValue()
      Specified by:
      getBitsPerValue in class PackedInts.Reader
      Returns:
      the number of bits used to store any given value. Note: This does not imply that memory usage is bitsPerValue * #values as implementations are free to use non-space-optimal packing of bits.
    • getMutable

      public PackedInts.Mutable getMutable()
    • getArray

      public Object getArray()
      Description copied from class: PackedInts.Reader
      Expert: if the bit-width of this reader matches one of java's native types, returns the underlying array (ie, byte[], short[], int[], long[]); else, returns null. Note that when accessing the array you must upgrade the type (bitwise AND with all ones), to interpret the full value as unsigned. Ie, bytes[idx]invalid input: '&'0xFF, shorts[idx]invalid input: '&'0xFFFF, etc.
      Overrides:
      getArray in class PackedInts.Reader
    • hasArray

      public boolean hasArray()
      Description copied from class: PackedInts.Reader
      Returns true if this implementation is backed by a native java array.
      Overrides:
      hasArray in class PackedInts.Reader
      See Also:
    • set

      public void set(int index, long value)
      Description copied from class: PackedInts.Mutable
      Set the value at the given index in the array.
      Specified by:
      set in class PackedInts.Mutable
      Parameters:
      index - where the value should be positioned.
      value - a value conforming to the constraints set by the array.
    • clear

      public void clear()
      Description copied from class: PackedInts.Mutable
      Sets all values to 0.
      Overrides:
      clear in class PackedInts.Mutable
    • resize

      public GrowableWriter resize(int newSize)
    • get

      public int get(int index, long[] arr, int off, int len)
      Description copied from class: PackedInts.Reader
      Bulk get: read at least one and at most len longs starting from index into arr[off:off+len] and return the actual number of values that have been read.
      Overrides:
      get in class PackedInts.Reader
    • set

      public int set(int index, long[] arr, int off, int len)
      Description copied from class: PackedInts.Mutable
      Bulk set: set at least one and at most len longs starting at off in arr into this mutable, starting at index. Returns the actual number of values that have been set.
      Overrides:
      set in class PackedInts.Mutable
    • fill

      public void fill(int fromIndex, int toIndex, long val)
      Description copied from class: PackedInts.Mutable
      Fill the mutable from fromIndex (inclusive) to toIndex (exclusive) with val.
      Overrides:
      fill in class PackedInts.Mutable
    • ramBytesUsed

      public long ramBytesUsed()
      Description copied from class: PackedInts.Reader
      Return the in-memory size in bytes.
      Specified by:
      ramBytesUsed in class PackedInts.Reader
    • save

      public void save(DataOutput out) throws IOException
      Description copied from class: PackedInts.Mutable
      Save this mutable into out. Instantiating a reader from the generated data will return a reader with the same number of bits per value.
      Overrides:
      save in class PackedInts.Mutable
      Throws:
      IOException