Class SparseArrayLinkedList<E>


  • public final class SparseArrayLinkedList<E>
    extends java.lang.Object
    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.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(E e)
      Appends e to the end of this list.
      static <E> void addToSparseArrayList​(java.util.List<org.apache.activemq.artemis.utils.collections.SparseArrayLinkedList.SparseArray<E>> sparseArrayList, E e, int sparseArrayCapacity)  
      long clear​(java.util.function.Consumer<? super E> consumer)
      Clear while consuming (using the given consumer all the elements of this list.
      static <E> long clearSparseArrayList​(java.util.List<org.apache.activemq.artemis.utils.collections.SparseArrayLinkedList.SparseArray<E>> sparseArrayList, java.util.function.Consumer<? super E> consumer)  
      long remove​(java.util.function.Predicate<? super E> filter)
      Removes any element of the list matching the given predicate.
      static <E> long removeFromSparseArrayList​(java.util.List<org.apache.activemq.artemis.utils.collections.SparseArrayLinkedList.SparseArray<E>> sparseArrayList, java.util.function.Predicate<? super E> filter)  
      long size()
      Returns the number of elements of this list.
      int sparseArrayCapacity()
      Returns the configured capacity of each sparse array/chunk.
      int sparseArraysCount()
      Returns the number of sparse arrays/chunks of this list.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SparseArrayLinkedList

        public SparseArrayLinkedList()
      • SparseArrayLinkedList

        public SparseArrayLinkedList​(int sparseArrayCapacity)
    • Method Detail

      • removeFromSparseArrayList

        public static <E> long removeFromSparseArrayList​(java.util.List<org.apache.activemq.artemis.utils.collections.SparseArrayLinkedList.SparseArray<E>> sparseArrayList,
                                                         java.util.function.Predicate<? super E> filter)
      • addToSparseArrayList

        public static <E> void addToSparseArrayList​(java.util.List<org.apache.activemq.artemis.utils.collections.SparseArrayLinkedList.SparseArray<E>> sparseArrayList,
                                                    E e,
                                                    int sparseArrayCapacity)
      • clearSparseArrayList

        public static <E> long clearSparseArrayList​(java.util.List<org.apache.activemq.artemis.utils.collections.SparseArrayLinkedList.SparseArray<E>> sparseArrayList,
                                                    java.util.function.Consumer<? super E> consumer)
      • add

        public void add​(E e)
        Appends e to the end of this list.
      • remove

        public long remove​(java.util.function.Predicate<? super E> filter)
        Removes any element of the list matching the given predicate.
      • clear

        public long clear​(java.util.function.Consumer<? super E> consumer)
        Clear while consuming (using the given consumer all the elements of this list.
      • size

        public long size()
        Returns the number of elements of this list.
      • sparseArrayCapacity

        public int sparseArrayCapacity()
        Returns the configured capacity of each sparse array/chunk.
      • sparseArraysCount

        public int sparseArraysCount()
        Returns the number of sparse arrays/chunks of this list.