This class also provides additional primitive accessor methods. This allows users to invoke {@code get} and {@code set} without marshalling primitivetypes to their {@link Integer} equivalents unnecessarily.
The {@code get} operation runs in logarithmic time. The {@code set}operation runs in consant time if setting an existing non-zero value to a non-zero value. However, if the {@code set} invocation sets a zero value tonon-zero, the operation is linear with the size of the array.
Instance offer a space savings of retaining only the non-zero indices and values. For large array with only a few values set, this offers a huge savings. However, as the cardinality of the array grows in relation to its size, a dense {@code int[]} array will offer better performance in both spaceand time. This is especially true if the sparse array instance approaches a cardinality to size ratio of {@code .5}.
This class supports iterating over the non-zero indices and values in the array via the {@link #iterator()} method. The indices will be returned insorted order. In cases where both the values and indices are needed, iteration will be faster, {@code O(k)}, than using {@link #getElementIndices()} and {@link #getPrimitive(int)} together, {@code O(k log(k))}, where {@code k} is the number of non-zero indices. The iteratorreturned by this class is not thread-safe and will not throw an exception if the array is concurrently modified during iteration. @see SparseArray
|
|
|
|
|
|