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