public class SparseHashedDoubleArray extends SparseDoubleArray
SparseDoubleArray
implementation based on a
TIntDoubleHashMap
. Unlike the SparseBinSearchDoubleArray
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.
SparseDoubleArray.DualEntry, SparseDoubleArray.Entry
DEFAULT_CAPACITY, length
Constructor and Description |
---|
SparseHashedDoubleArray(double[] values) |
SparseHashedDoubleArray(int length)
Construct the array with the given length
|
SparseHashedDoubleArray(int length,
float density)
Construct the array with the given length and expected density
|
SparseHashedDoubleArray(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.
|
SparseDoubleArray |
copy()
Deep copy the array.
|
Iterable<SparseDoubleArray.Entry> |
entries()
Provide an iterator over the non-zero values.
|
boolean |
equals(Object obj) |
double |
get(int key)
Get the value at the given index.
|
int |
hashCode() |
double |
increment(int key,
double value)
Increment the value at the given index.
|
int[] |
indices() |
boolean |
isUsed(int key)
Check whether the given index is used (i.e.
|
SparseDoubleArray |
reverse()
Reverse the elements, returning this.
|
double |
set(int key,
double value)
Set the value at the given index.
|
int |
used() |
double[] |
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 SparseHashedDoubleArray(double[] values)
values
- public SparseHashedDoubleArray(int length)
length
- the lengthpublic SparseHashedDoubleArray(int length, int capacity)
length
- the lengthcapacity
- the capacitypublic SparseHashedDoubleArray(int length, float density)
length
- the lengthdensity
- the densitypublic double increment(int key, double value)
SparseDoubleArray
increment
in class SparseDoubleArray
key
- the indexvalue
- the amount to increment by.public int[] indices()
indices
in class SparseDoubleArray
public double[] values()
values
in class SparseDoubleArray
public Iterable<SparseDoubleArray.Entry> entries()
SparseDoubleArray
Note: the SparseDoubleArray.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 SparseDoubleArray.Entry
has no effect
on the actual array).
entries
in class SparseDoubleArray
public double get(int key)
SparseDoubleArray
get
in class SparseDoubleArray
key
- the indexpublic boolean isUsed(int key)
SparseDoubleArray
isUsed
in class SparseDoubleArray
key
- the indexpublic double set(int key, double value)
SparseDoubleArray
set
in class SparseDoubleArray
key
- the index.value
- the value to set.public int used()
used
in class SparseDoubleArray
public void compact()
SparseDoubleArray
compact
in class SparseDoubleArray
public SparseDoubleArray copy()
SparseDoubleArray
copy
in class SparseDoubleArray
public SparseDoubleArray reverse()
SparseDoubleArray
reverse
in class SparseDoubleArray