Package ints

Class PackedIntArray

java.lang.Object
ints.PackedIntArray
All Implemented Interfaces:
IntArray

public final class PackedIntArray extends Object implements IntArray

Class PackedIntArray represents an immutable array of nonnegative integer values, which are stored in compressed form.

Instances of PackedIntArray are immutable.
  • Constructor Details

    • PackedIntArray

      public PackedIntArray(int[] ia, int valueSize)
      Constructs a new PackedIntArray instance from the specified data.
      Parameters:
      ia - an array of nonnegative integer values
      valueSize - the exclusive end of the range of non-negative array values
      Throws:
      IllegalArgumentException - if valueSize < 1
      IllegalArgumentException - if (ia[j] < 0 || ia[j] > valueSize) for any index j satisfying (j >= 0 && j < ia.length)
      NullPointerException - if ia == null
    • PackedIntArray

      public PackedIntArray(IntList il, int valueSize)
      Constructs a new PackedIntArray instance from the specified data.
      Parameters:
      il - an array of nonnegative integer values
      valueSize - the exclusive end of the range of non-negative array values
      Throws:
      IllegalArgumentException - if valueSize < 1
      IllegalArgumentException - if (il.get(j) < 0 || il.get(j) > valueSize) for any index j satisfying (j >= 0 && j < il.size())
      NullPointerException - if il == null
  • Method Details

    • fromSignedByteArray

      public static PackedIntArray fromSignedByteArray(byte[] ba, int valueSize)
      Constructs and returns a new PackedIntArray instance from the specified data.
      Parameters:
      ba - an array of non-negative integer values
      valueSize - the exclusive end of the range of non-negative array values
      Returns:
      a new PackedIntArray instance
      Throws:
      IllegalArgumentException - if valueSize < 1
      IllegalArgumentException - if (ia[j] < 0 || ia[j] > valueSize) for any index j satisfying (j >= 0 && j < ia.length)
      NullPointerException - if ia == null
    • fromSignedByteArray

      public static PackedIntArray fromSignedByteArray(byte[] ba, int from, int to, int valueSize)
      Constructs a new PackedIntArray instance from the specified data.
      Parameters:
      ba - an array of non-negative integer values
      from - the first element to be included (inclusive)
      to - the last element to be included (exclusive)
      valueSize - the exclusive end of the range of non-negative array values
      Returns:
      a new PackedIntArray instance
      Throws:
      IllegalArgumentException - if valueSize < 1
      IllegalArgumentException - if (ia[j] < 0 || ia[j] > valueSize) for any index j satisfying (j >= 0 && j < ia.length)
      IndexOutOfBoundsException - if from < 0 || to > ia.length
      NegativeArraySizeException - if to > from
      NullPointerException - if ia == null
    • fromUnsignedByteArray

      public static PackedIntArray fromUnsignedByteArray(byte[] ba, int valueSize)
      Constructs a new PackedIntArray instance from the specified data.
      Parameters:
      ba - an array of non-negative integer values represented as unsigned bytes
      valueSize - the exclusive end of the range of non-negative array values
      Returns:
      a new PackedIntArray instance
      Throws:
      IllegalArgumentException - if valueSize < 1
      IllegalArgumentException - if (ia[j] < 0 || ia[j] > valueSize) for any index j satisfying (j >= 0 && j < ia.length)
      NullPointerException - if ia == null
    • fromUnsignedByteArray

      public static PackedIntArray fromUnsignedByteArray(byte[] ba, int from, int to, int valueSize)
      Constructs a new PackedIntArray instance from the specified data.
      Parameters:
      ba - an array of non-negative integer values represented as unsigned bytes
      from - the first element to be included (inclusive)
      to - the last element to be included (exclusive)
      valueSize - the exclusive end of the range of non-negative array values
      Returns:
      a new PackedIntArray instance
      Throws:
      IllegalArgumentException - if valueSize < 1
      IllegalArgumentException - if (ia[j] < 0 || ia[j] > valueSize) for any index j satisfying (j >= 0 && j < ia.length)
      IndexOutOfBoundsException - if from < 0 || to > ia.length
      NegativeArraySizeException - if to > from
      NullPointerException - if ia == null
    • fromUnsignedTwoByteArray

      public static PackedIntArray fromUnsignedTwoByteArray(byte[] ba, int valueSize)
      Constructs a new PackedIntArray instance from the specified data. The specified array represents ba.length/2 unsigned two-byte values. The j-th unsigned two-byte value is stored in array elements 2*j and (2*j + 1), with the higher-order byte stored in element 2*j.
      Parameters:
      ba - an array of non-negative integer values represented as unsigned two-byte integers.
      valueSize - the exclusive end of the range of non-negative array values
      Returns:
      a new PackedIntArray instance
      Throws:
      IllegalArgumentException - if valueSize < 1
      IllegalArgumentException - if (ia[j] < 0 || ia[j] > valueSize) for any index j satisfying (j >= 0 && j < ia.length)
      IllegalArgumentException - if (ba.length & 1) != 0
      NullPointerException - if ia == null
    • size

      public int size()
      Description copied from interface: IntArray
      Returns the number of elements in this IntArray.
      Specified by:
      size in interface IntArray
      Returns:
      the number of elements in this IntArray
    • get

      public int get(int index)
      Description copied from interface: IntArray
      Returns the specified array element.
      Specified by:
      get in interface IntArray
      Parameters:
      index - an array index
      Returns:
      the specified array element