- Enclosing class:
- PackedArray
-
Method Summary
Modifier and TypeMethodDescriptionvoidclear(byte[] array) Sets all components of the given packed array to 0.byte[]create(int length) Creates abytearray that can store a packed array having the given number of components.byte[]create(PackedArray.IndexedLongValueProvider valueProvider, int length) Returns abytearray that represents a packed array having the given number of components.longget(byte[] array, int idx) Returns the value of a component in a packed array.intThe number of bits of a single component.intnumBytes(int length) Returns the number of bytes needed to store a packed array having the given number of components.intnumEqualComponents(byte[] array1, byte[] array2, int length) Returns the number of equal components of two packed arrays with given length.readIterator(byte[] array, int length) Returns aPackedArray.PackedArrayReadIteratorto read the values of all components in sequential order.longset(byte[] array, int idx, long value) Sets a component in a packed array to the given value and returns the previous value.longupdate(byte[] array, int idx, long value, LongBinaryOperator operator) Updates a component in a packed array using the given value and a binary operator that computes the update value from the previous value and the given value.
-
Method Details
-
numBytes
int numBytes(int length) Returns the number of bytes needed to store a packed array having the given number of components.- Parameters:
length- the length of the packed array- Returns:
- the number of bytes
-
create
byte[] create(int length) Creates abytearray that can store a packed array having the given number of components.All components of the byte array are initially 0, which also corresponds to 0 values in the packed array.
- Parameters:
length- the length of the packed array- Returns:
- a byte array representing the packed array
-
create
Returns abytearray that represents a packed array having the given number of components. The initial values are taken from the givenPackedArray.IndexedLongValueProvider.- Parameters:
valueProvider- a value providerlength- the length of the packed array- Returns:
- a byte array representing the packed array
-
get
long get(byte[] array, int idx) Returns the value of a component in a packed array.If the given index is not valid, the behavior of this function is undefined.
- Parameters:
array- a byte array representing the packed arrayidx- the index of the component- Returns:
- the value of the component
-
set
long set(byte[] array, int idx, long value) Sets a component in a packed array to the given value and returns the previous value.Only the lowest
getBitSize()bits of the given value are used for setting the new value.If the given index is not valid, the behavior of this function is undefined.
- Parameters:
array- a byte array representing the packed arrayidx- the index of the componentvalue- the new value- Returns:
- the previous value of the component
-
update
Updates a component in a packed array using the given value and a binary operator that computes the update value from the previous value and the given value.The given operator will get the old value of the component as first argument and the given value as second argument. Only the lowest
getBitSize()bits of the result are used for setting the new value.If the given index is not valid, the behavior of this function is undefined.
- Parameters:
array- a byte array representing the packed arrayidx- the index of the componentvalue- a valueoperator- a binary operator- Returns:
- the previous value of the component
- Throws:
NullPointerException- if operator isnull
-
getBitSize
int getBitSize()The number of bits of a single component.- Returns:
- the number of bits
-
numEqualComponents
int numEqualComponents(byte[] array1, byte[] array2, int length) Returns the number of equal components of two packed arrays with given length.If the arrays have been initialized using
create(int)with a different length than the given length, the behavior of this method is not defined.- Parameters:
array1- the first packed arrayarray2- the second packed arraylength- the total number of components- Returns:
- the number of equal components
-
clear
void clear(byte[] array) Sets all components of the given packed array to 0.- Parameters:
array- a packed array
-
readIterator
Returns aPackedArray.PackedArrayReadIteratorto read the values of all components in sequential order.- Parameters:
array- the packed arraylength- the number of components of the packed array- Returns:
- a read iterator
- Throws:
NullPointerException- if array is null
-