public class SparseArray extends java.lang.Object implements java.lang.Iterable<SparseArray.Entry>, java.io.Serializable
| Modifier and Type | Class and Description |
|---|---|
class |
SparseArray.Entry
The entry in a sparse array of double values.
|
| Constructor and Description |
|---|
SparseArray()
Constructor.
|
SparseArray(int initialCapacity)
Constructor.
|
SparseArray(java.util.List<SparseArray.Entry> entries)
Constructor.
|
SparseArray(java.util.stream.Stream<SparseArray.Entry> stream)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
append(int i,
double x)
Append an entry to the array, optimizing for the case where the
index is greater than all existing indices in the array.
|
double |
get(int i)
Returns the value of i-th entry.
|
boolean |
isEmpty()
Returns true if the array is empty.
|
java.util.Iterator<SparseArray.Entry> |
iterator()
Returns an iterator of nonzero entries.
|
void |
remove(int i)
Removes an entry.
|
boolean |
set(int i,
double x)
Sets or add an entry.
|
int |
size()
Returns the number of nonzero entries.
|
void |
sort()
Sorts the array elements such that the indices are in ascending order.
|
java.util.stream.Stream<SparseArray.Entry> |
stream()
Returns the stream of nonzero entries.
|
java.lang.String |
toString() |
public SparseArray()
public SparseArray(int initialCapacity)
initialCapacity - the initial capacity.public SparseArray(java.util.List<SparseArray.Entry> entries)
public SparseArray(java.util.stream.Stream<SparseArray.Entry> stream)
public java.lang.String toString()
toString in class java.lang.Objectpublic int size()
public boolean isEmpty()
public java.util.Iterator<SparseArray.Entry> iterator()
iterator in interface java.lang.Iterable<SparseArray.Entry>public java.util.stream.Stream<SparseArray.Entry> stream()
public void sort()
public double get(int i)
i - the index of entry.public boolean set(int i,
double x)
i - the index of entry.x - the value of entry.public void append(int i,
double x)
i - the index of entry.x - the value of entry.public void remove(int i)
i - the index of entry.