public class SparseHashedLongArray extends SparseLongArray
SparseLongArray implementation based on a
TIntLongHashMap. Unlike the SparseBinSearchLongArray
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.
SparseLongArray.DualEntry, SparseLongArray.EntryDEFAULT_CAPACITY, length| Constructor and Description |
|---|
SparseHashedLongArray(int length)
Construct the array with the given length
|
SparseHashedLongArray(int length,
float density)
Construct the array with the given length and expected density
|
SparseHashedLongArray(int length,
int capacity)
Construct the array with the given length and capacity for non-zero elements
|
SparseHashedLongArray(long[] values) |
| Modifier and Type | Method and Description |
|---|---|
void |
compact()
Compact the space being used by the array if possible.
|
SparseLongArray |
copy()
Deep copy the array.
|
Iterable<SparseLongArray.Entry> |
entries()
Provide an iterator over the non-zero values.
|
boolean |
equals(Object obj) |
long |
get(int key)
Get the value at the given index.
|
int |
hashCode() |
long |
increment(int key,
long value)
Increment the value at the given index.
|
int[] |
indices() |
boolean |
isUsed(int key)
Check whether the given index is used (i.e.
|
SparseLongArray |
reverse()
Reverse the elements, returning this.
|
long |
set(int key,
long value)
Set the value at the given index.
|
int |
used() |
long[] |
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, writeBinarypublic SparseHashedLongArray(long[] values)
values - public SparseHashedLongArray(int length)
length - the lengthpublic SparseHashedLongArray(int length, int capacity)
length - the lengthcapacity - the capacitypublic SparseHashedLongArray(int length, float density)
length - the lengthdensity - the densitypublic long increment(int key, long value)
SparseLongArrayincrement in class SparseLongArraykey - the indexvalue - the amount to increment by.public int[] indices()
indices in class SparseLongArraypublic long[] values()
values in class SparseLongArraypublic Iterable<SparseLongArray.Entry> entries()
SparseLongArray
Note: the SparseLongArray.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 SparseLongArray.Entry has no effect
on the actual array).
entries in class SparseLongArraypublic long get(int key)
SparseLongArrayget in class SparseLongArraykey - the indexpublic boolean isUsed(int key)
SparseLongArrayisUsed in class SparseLongArraykey - the indexpublic long set(int key, long value)
SparseLongArrayset in class SparseLongArraykey - the index.value - the value to set.public int used()
used in class SparseLongArraypublic void compact()
SparseLongArraycompact in class SparseLongArraypublic SparseLongArray copy()
SparseLongArraycopy in class SparseLongArraypublic SparseLongArray reverse()
SparseLongArrayreverse in class SparseLongArray