Class SparseArrayLinkedList<E>
java.lang.Object
org.apache.activemq.artemis.utils.collections.SparseArrayLinkedList<E>
This list share the same motivation and structure of https://en.wikipedia.org/wiki/Unrolled_linked_list: it's a
linked list of arrays/chunks of
T.
Differently from an UnrolledLinkedList this list doesn't optimize addition and removal to achieve a balanced
utilization among chunks ie a chunk is removed only if empty and chunks can't be merged. This list has been optimized
for small-sized chunks (ideally <= 32 elements): this allow search/removal to be performed with a greedy approach
despite a sparse chunk utilization (ie chunks contains few sparse elements).
From the memory footprint's point of view, this list won't remove the last remaining array although empty to optimize the case where its capacity would be enough to hold incoming elements, hence saving a new array allocation.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAppendseto the end of this list.static <E> voidaddToSparseArrayList(List<org.apache.activemq.artemis.utils.collections.SparseArrayLinkedList.SparseArray<E>> sparseArrayList, E e, int sparseArrayCapacity) longClear while consuming (using the givenconsumerall the elements of this list.static <E> longclearSparseArrayList(List<org.apache.activemq.artemis.utils.collections.SparseArrayLinkedList.SparseArray<E>> sparseArrayList, Consumer<? super E> consumer) longRemoves any element of the list matching the given predicate.static <E> longremoveFromSparseArrayList(List<org.apache.activemq.artemis.utils.collections.SparseArrayLinkedList.SparseArray<E>> sparseArrayList, Predicate<? super E> filter) longsize()Returns the number of elements of this list.intReturns the configured capacity of each sparse array/chunk.intReturns the number of sparse arrays/chunks of this list.
-
Constructor Details
-
SparseArrayLinkedList
public SparseArrayLinkedList() -
SparseArrayLinkedList
public SparseArrayLinkedList(int sparseArrayCapacity)
-
-
Method Details
-
removeFromSparseArrayList
-
addToSparseArrayList
public static <E> void addToSparseArrayList(List<org.apache.activemq.artemis.utils.collections.SparseArrayLinkedList.SparseArray<E>> sparseArrayList, E e, int sparseArrayCapacity) -
clearSparseArrayList
-
add
Appendseto the end of this list. -
remove
Removes any element of the list matching the given predicate. -
clear
Clear while consuming (using the givenconsumerall the elements of this list. -
size
public long size()Returns the number of elements of this list.- Returns:
- the number of elements of this list
-
sparseArrayCapacity
public int sparseArrayCapacity()Returns the configured capacity of each sparse array/chunk.- Returns:
- the configured capacity of each sparse array/chunk
-
sparseArraysCount
public int sparseArraysCount()Returns the number of sparse arrays/chunks of this list.- Returns:
- the number of sparse arrays/chunks of this list
-