Package ints
Class PackedIntArray
java.lang.Object
ints.PackedIntArray
- All Implemented Interfaces:
IntArray
Class PackedIntArray represents an immutable array of
nonnegative integer values, which are stored in compressed form.
PackedIntArray are immutable.-
Constructor Summary
ConstructorsConstructorDescriptionPackedIntArray(int[] ia, int valueSize) Constructs a newPackedIntArrayinstance from the specified data.PackedIntArray(IntList il, int valueSize) Constructs a newPackedIntArrayinstance from the specified data. -
Method Summary
Modifier and TypeMethodDescriptionstatic PackedIntArrayfromSignedByteArray(byte[] ba, int valueSize) Constructs and returns a newPackedIntArrayinstance from the specified data.static PackedIntArrayfromSignedByteArray(byte[] ba, int from, int to, int valueSize) Constructs a newPackedIntArrayinstance from the specified data.static PackedIntArrayfromUnsignedByteArray(byte[] ba, int valueSize) Constructs a newPackedIntArrayinstance from the specified data.static PackedIntArrayfromUnsignedByteArray(byte[] ba, int from, int to, int valueSize) Constructs a newPackedIntArrayinstance from the specified data.static PackedIntArrayfromUnsignedTwoByteArray(byte[] ba, int valueSize) Constructs a newPackedIntArrayinstance from the specified data.intget(int index) Returns the specified array element.intsize()Returns the number of elements in thisIntArray.
-
Constructor Details
-
PackedIntArray
public PackedIntArray(int[] ia, int valueSize) Constructs a newPackedIntArrayinstance from the specified data.- Parameters:
ia- an array of nonnegative integer valuesvalueSize- the exclusive end of the range of non-negative array values- Throws:
IllegalArgumentException- ifvalueSize < 1IllegalArgumentException- if(ia[j] < 0 || ia[j] > valueSize)for any indexjsatisfying(j >= 0 && j < ia.length)NullPointerException- ifia == null
-
PackedIntArray
Constructs a newPackedIntArrayinstance from the specified data.- Parameters:
il- an array of nonnegative integer valuesvalueSize- the exclusive end of the range of non-negative array values- Throws:
IllegalArgumentException- ifvalueSize < 1IllegalArgumentException- if(il.get(j) < 0 || il.get(j) > valueSize)for any indexjsatisfying(j >= 0 && j < il.size())NullPointerException- ifil == null
-
-
Method Details
-
fromSignedByteArray
Constructs and returns a newPackedIntArrayinstance from the specified data.- Parameters:
ba- an array of non-negative integer valuesvalueSize- the exclusive end of the range of non-negative array values- Returns:
- a new
PackedIntArrayinstance - Throws:
IllegalArgumentException- ifvalueSize < 1IllegalArgumentException- if(ia[j] < 0 || ia[j] > valueSize)for any indexjsatisfying(j >= 0 && j < ia.length)NullPointerException- ifia == null
-
fromSignedByteArray
Constructs a newPackedIntArrayinstance from the specified data.- Parameters:
ba- an array of non-negative integer valuesfrom- 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
PackedIntArrayinstance - Throws:
IllegalArgumentException- ifvalueSize < 1IllegalArgumentException- if(ia[j] < 0 || ia[j] > valueSize)for any indexjsatisfying(j >= 0 && j < ia.length)IndexOutOfBoundsException- iffrom < 0 || to > ia.lengthNegativeArraySizeException- ifto > fromNullPointerException- ifia == null
-
fromUnsignedByteArray
Constructs a newPackedIntArrayinstance from the specified data.- Parameters:
ba- an array of non-negative integer values represented as unsigned bytesvalueSize- the exclusive end of the range of non-negative array values- Returns:
- a new
PackedIntArrayinstance - Throws:
IllegalArgumentException- ifvalueSize < 1IllegalArgumentException- if(ia[j] < 0 || ia[j] > valueSize)for any indexjsatisfying(j >= 0 && j < ia.length)NullPointerException- ifia == null
-
fromUnsignedByteArray
Constructs a newPackedIntArrayinstance from the specified data.- Parameters:
ba- an array of non-negative integer values represented as unsigned bytesfrom- 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
PackedIntArrayinstance - Throws:
IllegalArgumentException- ifvalueSize < 1IllegalArgumentException- if(ia[j] < 0 || ia[j] > valueSize)for any indexjsatisfying(j >= 0 && j < ia.length)IndexOutOfBoundsException- iffrom < 0 || to > ia.lengthNegativeArraySizeException- ifto > fromNullPointerException- ifia == null
-
fromUnsignedTwoByteArray
Constructs a newPackedIntArrayinstance from the specified data. The specified array representsba.length/2unsigned two-byte values. Thej-th unsigned two-byte value is stored in array elements2*jand(2*j + 1), with the higher-order byte stored in element2*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
PackedIntArrayinstance - Throws:
IllegalArgumentException- ifvalueSize < 1IllegalArgumentException- if(ia[j] < 0 || ia[j] > valueSize)for any indexjsatisfying(j >= 0 && j < ia.length)IllegalArgumentException- if(ba.length & 1) != 0NullPointerException- ifia == null
-
size
public int size()Description copied from interface:IntArrayReturns the number of elements in thisIntArray. -
get
public int get(int index) Description copied from interface:IntArrayReturns the specified array element.
-