public class SparseBinSearchFloatArray extends SparseFloatArray
Element access has worst-case O(log n) performance. Appends (where the index being added is greater than the existing indices) has O(1) complexity. Random puts have worst case O(n + log n) complexity. Complexity for getting values by increasing index for iteration through the non-zero values is O(1).
In summary, this implementation has good access performance, and is fast for appending values, but slow for putting at random indices. It is is optimal for a scenario where you first create the sparse array and put values in order of increasing indices, and later use the array mostly for reading.
SparseFloatArray.DualEntry, SparseFloatArray.Entry
Modifier and Type | Field and Description |
---|---|
protected int[] |
keys |
protected int |
used |
protected float[] |
values |
DEFAULT_CAPACITY, length
Constructor and Description |
---|
SparseBinSearchFloatArray(float[] values)
Construct from an existing array of values
|
SparseBinSearchFloatArray(int length)
Construct the array with the given length
|
SparseBinSearchFloatArray(int length,
float density)
Construct the array with the given length and expected density
|
SparseBinSearchFloatArray(int length,
int capacity)
Construct the array with the given length and capacity for non-zero elements
|
SparseBinSearchFloatArray(int length,
int used,
int[] keys,
float[] values)
Generate a new
SparseBinSearchFloatArray wrapper which works around
an existing array of keys and values |
Modifier and Type | Method and Description |
---|---|
void |
compact()
Compact the space being used by the array if possible.
|
SparseFloatArray |
copy()
Deep copy the array.
|
Iterable<SparseFloatArray.Entry> |
entries()
Provide an iterator over the non-zero values.
|
boolean |
equals(Object obj) |
float |
get(int key)
Get the value at the given index.
|
int |
hashCode() |
float |
increment(int key,
float value)
Increment the value at the given index.
|
int[] |
indices() |
boolean |
isUsed(int key)
Check whether the given index is used (i.e.
|
SparseFloatArray |
reverse()
Reverse the elements, returning this.
|
float |
set(int key,
float value)
Set the value at the given index.
|
Iterable<SparseFloatArray.DualEntry> |
unionEntries(SparseBinSearchFloatArray otherArray)
Provide an iterator over the union of values present in
both this array and another array.
|
Iterable<SparseFloatArray.DualEntry> |
unionEntries(SparseFloatArray otherArray)
Provide an iterator over the union of values present in
both this array and another array.
|
int |
used() |
float[] |
values() |
add, addInplace, asciiHeader, binaryHeader, concatenate, concatenate, concatenateArrays, density, dotProduct, intersectEntries, length, maxIndex, maxValue, minIndex, minValue, multiply, multiplyInplace, readASCII, readBinary, setLength, size, subtract, subtractInplace, sumValues, sumValuesSquared, toArray, toArray, writeASCII, writeBinary
public SparseBinSearchFloatArray(float[] values)
values
- the valuespublic SparseBinSearchFloatArray(int length, int used, int[] keys, float[] values)
SparseBinSearchFloatArray
wrapper which works around
an existing array of keys and valueslength
- used
- keys
- values
- public SparseBinSearchFloatArray(int length)
length
- the lengthpublic SparseBinSearchFloatArray(int length, int capacity)
length
- the lengthcapacity
- the capacitypublic SparseBinSearchFloatArray(int length, float density)
length
- the lengthdensity
- the densitypublic int[] indices()
indices
in class SparseFloatArray
public float[] values()
values
in class SparseFloatArray
public Iterable<SparseFloatArray.DualEntry> unionEntries(SparseFloatArray otherArray)
SparseFloatArray
Note: the SparseFloatArray.DualEntry
returned by the iterator
is always the same object. In addition, the iterator
cannot affect the value of anything in the array (i.e.
changing anything in the SparseFloatArray.DualEntry
has no effect
on the actual array).
unionEntries
in class SparseFloatArray
otherArray
- the second arraypublic Iterable<SparseFloatArray.DualEntry> unionEntries(SparseBinSearchFloatArray otherArray)
Note: the SparseFloatArray.DualEntry
returned by the iterator
is always the same object. In addition, the iterator
cannot affect the value of anything in the array (i.e.
changing anything in the SparseFloatArray.DualEntry
has no effect
on the actual array).
otherArray
- the second arraypublic Iterable<SparseFloatArray.Entry> entries()
SparseFloatArray
Note: the SparseFloatArray.Entry
returned by the iterator
is always the same object. In addition, the iterator
cannot affect the value of anything in the array (i.e.
changing anything in the SparseFloatArray.Entry
has no effect
on the actual array).
entries
in class SparseFloatArray
public float get(int key)
SparseFloatArray
get
in class SparseFloatArray
key
- the indexpublic boolean isUsed(int key)
SparseFloatArray
isUsed
in class SparseFloatArray
key
- the indexpublic float set(int key, float value)
SparseFloatArray
set
in class SparseFloatArray
key
- the index.value
- the value to set.public float increment(int key, float value)
SparseFloatArray
increment
in class SparseFloatArray
key
- the indexvalue
- the amount to increment by.public int used()
used
in class SparseFloatArray
public void compact()
SparseFloatArray
compact
in class SparseFloatArray
public SparseFloatArray copy()
SparseFloatArray
copy
in class SparseFloatArray
public SparseFloatArray reverse()
SparseFloatArray
reverse
in class SparseFloatArray