Class SparseIntArray
java.lang.Object
smile.util.SparseIntArray
- All Implemented Interfaces:
 Serializable, Iterable<SparseIntArray.Entry>
Sparse array of integers.
- See Also:
 
- 
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordThe entry in a sparse array of double values. - 
Constructor Summary
ConstructorsConstructorDescriptionConstructor.SparseIntArray(int initialCapacity) Constructor.SparseIntArray(Collection<SparseIntArray.Entry> entries) Constructor.SparseIntArray(Stream<SparseIntArray.Entry> stream) Constructor. - 
Method Summary
Modifier and TypeMethodDescriptionvoidappend(int i, int x) Append an entry to the array, optimizing for the case where the index is greater than all existing indices in the array.voidforEach(IntArrayElementConsumer action) Performs an action for each nonzero entry.doubleget(int i) Returns the value of i-th entry.Returns the stream of the indices of nonzero entries.booleanisEmpty()Returns true if the array is empty.iterator()map(IntArrayElementFunction mapper) Returns a stream consisting of the results of applying the given function to the nonzero entries.voidremove(int i) Removes an entry.booleanset(int i, int x) Sets or adds an entry.intsize()Returns the number of nonzero entries.voidsort()Sorts the array elements such that the indices are in ascending order.stream()Returns the stream of nonzero entries.toString()voidupdate(IntArrayElementFunction mapper) Updates each nonzero entry.Returns the stream of the values of nonzero entries.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface Iterable
forEach, spliterator 
- 
Constructor Details
- 
SparseIntArray
public SparseIntArray()Constructor. - 
SparseIntArray
public SparseIntArray(int initialCapacity) Constructor.- Parameters:
 initialCapacity- the initial capacity.
 - 
SparseIntArray
Constructor.- Parameters:
 entries- the nonzero entries.
 - 
SparseIntArray
Constructor.- Parameters:
 stream- the stream of nonzero entries.
 
 - 
 - 
Method Details
- 
toString
 - 
size
public int size()Returns the number of nonzero entries.- Returns:
 - the number of nonzero entries
 
 - 
isEmpty
public boolean isEmpty()Returns true if the array is empty.- Returns:
 - true if the array is empty.
 
 - 
forEach
Performs an action for each nonzero entry.- Parameters:
 action- a non-interfering action to perform on the nonzero entries.
 - 
map
Returns a stream consisting of the results of applying the given function to the nonzero entries.- Parameters:
 mapper- a non-interfering, stateless function to map each nonzero entry to new value.- Returns:
 - the stream of the new values of nonzero entries.
 
 - 
update
Updates each nonzero entry.- Parameters:
 mapper- a function to map each nonzero entry to new value.
 - 
iterator
- Specified by:
 iteratorin interfaceIterable<SparseIntArray.Entry>
 - 
stream
Returns the stream of nonzero entries.- Returns:
 - the stream of nonzero entries.
 
 - 
indexStream
Returns the stream of the indices of nonzero entries.- Returns:
 - the stream of the indices of nonzero entries.
 
 - 
valueStream
Returns the stream of the values of nonzero entries.- Returns:
 - the stream of the values of nonzero entries.
 
 - 
sort
public void sort()Sorts the array elements such that the indices are in ascending order. - 
get
public double get(int i) Returns the value of i-th entry.- Parameters:
 i- the index of entry.- Returns:
 - the value of entry, 0.0 if the index doesn't exist in the array.
 
 - 
set
public boolean set(int i, int x) Sets or adds an entry.- Parameters:
 i- the index of entry.x- the value of entry.- Returns:
 - true if a new entry added, false if an existing entry updated.
 
 - 
append
public void append(int i, int x) Append an entry to the array, optimizing for the case where the index is greater than all existing indices in the array.- Parameters:
 i- the index of entry.x- the value of entry.
 - 
remove
public void remove(int i) Removes an entry.- Parameters:
 i- the index of entry.
 
 -