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 newPackedIntArray
instance from the specified data.PackedIntArray
(IntList il, int valueSize) Constructs a newPackedIntArray
instance from the specified data. -
Method Summary
Modifier and TypeMethodDescriptionstatic PackedIntArray
fromSignedByteArray
(byte[] ba, int valueSize) Constructs and returns a newPackedIntArray
instance from the specified data.static PackedIntArray
fromSignedByteArray
(byte[] ba, int from, int to, int valueSize) Constructs a newPackedIntArray
instance from the specified data.static PackedIntArray
fromUnsignedByteArray
(byte[] ba, int valueSize) Constructs a newPackedIntArray
instance from the specified data.static PackedIntArray
fromUnsignedByteArray
(byte[] ba, int from, int to, int valueSize) Constructs a newPackedIntArray
instance from the specified data.static PackedIntArray
fromUnsignedTwoByteArray
(byte[] ba, int valueSize) Constructs a newPackedIntArray
instance from the specified data.int
get
(int index) Returns the specified array element.int
size()
Returns the number of elements in thisIntArray
.
-
Constructor Details
-
PackedIntArray
public PackedIntArray(int[] ia, int valueSize) Constructs a newPackedIntArray
instance 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 < 1
IllegalArgumentException
- if(ia[j] < 0 || ia[j] > valueSize)
for any indexj
satisfying(j >= 0 && j < ia.length)
NullPointerException
- ifia == null
-
PackedIntArray
Constructs a newPackedIntArray
instance 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 < 1
IllegalArgumentException
- if(il.get(j) < 0 || il.get(j) > valueSize)
for any indexj
satisfying(j >= 0 && j < il.size())
NullPointerException
- ifil == null
-
-
Method Details
-
fromSignedByteArray
Constructs and returns a newPackedIntArray
instance 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
PackedIntArray
instance - Throws:
IllegalArgumentException
- ifvalueSize < 1
IllegalArgumentException
- if(ia[j] < 0 || ia[j] > valueSize)
for any indexj
satisfying(j >= 0 && j < ia.length)
NullPointerException
- ifia == null
-
fromSignedByteArray
Constructs a newPackedIntArray
instance 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
PackedIntArray
instance - Throws:
IllegalArgumentException
- ifvalueSize < 1
IllegalArgumentException
- if(ia[j] < 0 || ia[j] > valueSize)
for any indexj
satisfying(j >= 0 && j < ia.length)
IndexOutOfBoundsException
- iffrom < 0 || to > ia.length
NegativeArraySizeException
- ifto > from
NullPointerException
- ifia == null
-
fromUnsignedByteArray
Constructs a newPackedIntArray
instance 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
PackedIntArray
instance - Throws:
IllegalArgumentException
- ifvalueSize < 1
IllegalArgumentException
- if(ia[j] < 0 || ia[j] > valueSize)
for any indexj
satisfying(j >= 0 && j < ia.length)
NullPointerException
- ifia == null
-
fromUnsignedByteArray
Constructs a newPackedIntArray
instance 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
PackedIntArray
instance - Throws:
IllegalArgumentException
- ifvalueSize < 1
IllegalArgumentException
- if(ia[j] < 0 || ia[j] > valueSize)
for any indexj
satisfying(j >= 0 && j < ia.length)
IndexOutOfBoundsException
- iffrom < 0 || to > ia.length
NegativeArraySizeException
- ifto > from
NullPointerException
- ifia == null
-
fromUnsignedTwoByteArray
Constructs a newPackedIntArray
instance from the specified data. The specified array representsba.length/2
unsigned two-byte values. Thej
-th unsigned two-byte value is stored in array elements2*j
and(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
PackedIntArray
instance - Throws:
IllegalArgumentException
- ifvalueSize < 1
IllegalArgumentException
- if(ia[j] < 0 || ia[j] > valueSize)
for any indexj
satisfying(j >= 0 && j < ia.length)
IllegalArgumentException
- if(ba.length & 1) != 0
NullPointerException
- ifia == null
-
size
public int size()Description copied from interface:IntArray
Returns the number of elements in thisIntArray
. -
get
public int get(int index) Description copied from interface:IntArray
Returns the specified array element.
-