public class SparseHashedFloatArray extends SparseFloatArray
SparseFloatArray
implementation based on a
TIntFloatHashMap
. Unlike the SparseBinSearchFloatArray
implementation, this class should be good for the case
where random insertion is used frequently (O(1) insert complexity).
In the worst-case search is O(n), although in practice it should be better.
Note that the entries()
method will in general not return
the entries in index order.
SparseFloatArray.DualEntry, SparseFloatArray.Entry
DEFAULT_CAPACITY, length
Constructor and Description |
---|
SparseHashedFloatArray(float[] values) |
SparseHashedFloatArray(int length)
Construct the array with the given length
|
SparseHashedFloatArray(int length,
float density)
Construct the array with the given length and expected density
|
SparseHashedFloatArray(int length,
int capacity)
Construct the array with the given length and capacity for non-zero elements
|
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.
|
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, unionEntries, writeASCII, writeBinary
public SparseHashedFloatArray(float[] values)
values
- public SparseHashedFloatArray(int length)
length
- the lengthpublic SparseHashedFloatArray(int length, int capacity)
length
- the lengthcapacity
- the capacitypublic SparseHashedFloatArray(int length, float density)
length
- the lengthdensity
- the densitypublic float increment(int key, float value)
SparseFloatArray
increment
in class SparseFloatArray
key
- the indexvalue
- the amount to increment by.public int[] indices()
indices
in class SparseFloatArray
public float[] values()
values
in class SparseFloatArray
public 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 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