Package ints

Class PackedIntArray

  • All Implemented Interfaces:
    IntArray

    public final class PackedIntArray
    extends java.lang.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 Summary

      Constructors 
      Constructor Description
      PackedIntArray​(int[] ia, int valueSize)
      Constructs a new PackedIntArray instance from the specified data.
      PackedIntArray​(IntList il, int valueSize)
      Constructs a new PackedIntArray instance from the specified data.
    • Constructor Detail

      • 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:
        java.lang.IllegalArgumentException - if valueSize < 1
        java.lang.IllegalArgumentException - if (ia[j] < 0 || ia[j] > valueSize) for any index j satisfying (j >= 0 && j < ia.length)
        java.lang.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:
        java.lang.IllegalArgumentException - if valueSize < 1
        java.lang.IllegalArgumentException - if (il.get(j) < 0 || il.get(j) > valueSize) for any index j satisfying (j >= 0 && j < il.size())
        java.lang.NullPointerException - if il == null
    • Method Detail

      • 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:
        java.lang.IllegalArgumentException - if valueSize < 1
        java.lang.IllegalArgumentException - if (ia[j] < 0 || ia[j] > valueSize) for any index j satisfying (j >= 0 && j < ia.length)
        java.lang.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:
        java.lang.IllegalArgumentException - if valueSize < 1
        java.lang.IllegalArgumentException - if (ia[j] < 0 || ia[j] > valueSize) for any index j satisfying (j >= 0 && j < ia.length)
        java.lang.IndexOutOfBoundsException - if from < 0 || to > ia.length
        java.lang.NegativeArraySizeException - if to > from
        java.lang.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:
        java.lang.IllegalArgumentException - if valueSize < 1
        java.lang.IllegalArgumentException - if (ia[j] < 0 || ia[j] > valueSize) for any index j satisfying (j >= 0 && j < ia.length)
        java.lang.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:
        java.lang.IllegalArgumentException - if valueSize < 1
        java.lang.IllegalArgumentException - if (ia[j] < 0 || ia[j] > valueSize) for any index j satisfying (j >= 0 && j < ia.length)
        java.lang.IndexOutOfBoundsException - if from < 0 || to > ia.length
        java.lang.NegativeArraySizeException - if to > from
        java.lang.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:
        java.lang.IllegalArgumentException - if valueSize < 1
        java.lang.IllegalArgumentException - if (ia[j] < 0 || ia[j] > valueSize) for any index j satisfying (j >= 0 && j < ia.length)
        java.lang.IllegalArgumentException - if (ba.length & 1) != 0
        java.lang.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