Class PackedVector

All Implemented Interfaces:
Serializable, Iterable<Number>, Collection<Number>, List<Number>, RandomAccess, SequencedCollection<Number>, CheckedContainer<Long>

final class PackedVector extends ArrayVector<Long>
A vector of integer values backed by an IntegerList. This offers a compressed storage using only the minimal amount of bits per value.
Since:
0.8
Version:
1.1
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      For cross-version compatibility.
      See Also:
    • MINIMAL_SIZE

      static final int MINIMAL_SIZE
      Minimal length for creating a packed vector. This is an arbitrary value that may change in any future version.
      See Also:
    • data

      private final IntegerList data
      The compressed list of integer values. This list can store values from 0 to delta inclusive.
    • increment

      private final long increment
      The value by which to multiply the data before to add the offset.
    • offset

      private final long offset
      The offset to add to the data in order to get the values to return.
  • Constructor Details

    • PackedVector

      private PackedVector(Vector source, long increment, long offset, int delta)
      Creates a new compressed vector initialized to a copy of the data provided by the given vector.
      Parameters:
      source - the vector to copy.
      increment - the common divisor of all (sample minus offset) values.
      offset - the minimal value in the source vector.
      delta - the maximal value in the source vector minus offset divided by increment.
  • Method Details

    • compress

      static PackedVector compress(Vector source, long min, long max)
      Creates a new compressed vector initialized to a copy of the data provided by the given vector. All values in the given vector shall be assignable to the long type (this is not verified).
      Parameters:
      source - the vector to copy.
      min - the minimal value in the given vector, inclusive.
      max - the maximal value in the given vector, inclusive.
      Returns:
      the compressed vector, or null if the vector cannot or should not be compressed.
    • getElementType

      public Class<Long> getElementType()
      Type of elements fixed to Long even if the actual storage used by this class is more compact. The reason for the Long type is that this class can return any value in the Long range, because of the offset.
      Specified by:
      getElementType in interface CheckedContainer<Long>
      Specified by:
      getElementType in class Vector
      Returns:
      the type of elements in this vector.
      See Also:
    • isSinglePrecision

      public boolean isSinglePrecision()
      Long values are not guaranteed to be convertible to single-precision floating point type.
      Overrides:
      isSinglePrecision in class Vector
      Returns:
      whether values in this vector can be casted to float primitive type.
      See Also:
    • size

      public int size()
      Returns the number of elements in this vector.
      Specified by:
      size in interface Collection<Number>
      Specified by:
      size in interface List<Number>
      Specified by:
      size in class Vector
      Returns:
      the number of elements in this vector.
    • doubleValue

      public double doubleValue(int index)
      Returns the value at the given index as a double primitive type.
      Specified by:
      doubleValue in class Vector
      Parameters:
      index - the index in the [0 … size-1] range.
      Returns:
      the value at the given index.
      See Also:
    • floatValue

      public float floatValue(int index)
      Returns the value at the given index as a float primitive type.
      Overrides:
      floatValue in class Vector
      Parameters:
      index - the index in the [0 … size-1] range.
      Returns:
      the value at the given index.
      See Also:
    • longValue

      public long longValue(int index)
      Returns the value at the given index as a long primitive type.
      Overrides:
      longValue in class Vector
      Parameters:
      index - the index in the [0 … size-1] range.
      Returns:
      the value at the given index.
    • stringValue

      public String stringValue(int index)
      Returns the string representation of the value at the given index.
      Specified by:
      stringValue in class Vector
      Parameters:
      index - the index in the [0 … size-1] range.
      Returns:
      a string representation of the value at the given index (may be null).
      See Also:
    • get

      public Number get(int index)
      Returns the value at the given index wrapped in a Long instance.
      Specified by:
      get in interface List<Number>
      Specified by:
      get in class Vector
      Parameters:
      index - the index in the [0 … size-1] range.
      Returns:
      the value at the given index (may be null).
    • set

      public Number set(int index, Number value)
      Sets the value at the given index and returns the previous value.
      Specified by:
      set in interface List<Number>
      Specified by:
      set in class Vector
      Parameters:
      index - the index in the [0 … size-1] range.
      value - the value to set at the given index.
      Returns:
      the value previously stored at the given index.
    • equals

      public boolean equals(Object other)
      Optimization of equals(…) method for the case where the other object is another PackedVector.
      Specified by:
      equals in interface Collection<Number>
      Specified by:
      equals in interface List<Number>
      Overrides:
      equals in class Vector
      Parameters:
      other - the other object to compare with this vector.
      Returns:
      true if the given object is a vector containing the same values than this vector.