Constructor and Description |
---|
VariableValueArray(int bitsPerValue,
int capacity)
Creates an instance.
|
Modifier and Type | Method and Description |
---|---|
static int |
calculateNeededBits(int number)
Calculates the number of bits that would be needed to store the given value.
|
VariableValueArray |
clone() |
int |
get(int index)
Returns a value.
|
long[] |
getBacking() |
int |
getBitsPerValue() |
int |
getCapacity() |
long |
getLargestPossibleValue() |
VariableValueArray |
increaseBitsPerValueTo(int newBitsPerValue)
Creates a new VariableValueArray with the contents of this one, and the given bits per
value.
|
void |
set(int index,
int value)
Sets a value.
|
public VariableValueArray(int bitsPerValue, int capacity)
bitsPerValue
- the number of bits into which each value must fitcapacity
- the number of entriespublic static int calculateNeededBits(int number)
number
- the valuepublic long getLargestPossibleValue()
public int get(int index)
index
- the entry to look upIndexOutOfBoundsException
- if index
is out of rangepublic void set(int index, int value)
index
- the entry to setvalue
- the value to set it toIndexOutOfBoundsException
- if index
is out of rangeIllegalArgumentException
- if value
is out of rangepublic VariableValueArray increaseBitsPerValueTo(int newBitsPerValue)
newBitsPerValue
- The new value. Must be larger than the current value ( getBitsPerValue()
).IllegalArgumentException
- If newBitsPerValue is less than or equal to the
current bits per value. Setting it to the same size would be a waste of resources,
and decreasing could lead to data loss.public VariableValueArray clone()
public long[] getBacking()
public int getCapacity()
public int getBitsPerValue()
Copyright © 2021. All rights reserved.