Class ChunkList<E>

  • Type Parameters:
    E - element type
    All Implemented Interfaces:
    java.lang.Iterable<E>, java.util.Collection<E>, java.util.List<E>

    public class ChunkList<E>
    extends java.util.AbstractSequentialList<E>
    Implementation of list similar to LinkedList, but stores elements in chunks of 32 elements.

    ArrayList has O(n) insertion and deletion into the middle of the list. ChunkList insertion and deletion are O(1).

    • Field Summary

      Modifier and Type Field Description
      private static int CHUNK_SIZE  
      private java.lang.Object[] first  
      private static int HEADER_SIZE  
      private static java.lang.Integer[] INTEGERS  
      private java.lang.Object[] last  
      private int size  
      • Fields inherited from class java.util.AbstractList

    • Constructor Summary

      Constructor Description
      Creates an empty ChunkList.
      ChunkList​(java.util.Collection<E> collection)
      Creates a ChunkList whose contents are a given Collection.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(int index, E element)  
      boolean add​(E element)  
      void clear()  
      private static java.lang.Object element​(java.lang.Object[] chunk, int index)  
      (package private) boolean isValid​(boolean fail)
      For debugging and testing.
      java.util.ListIterator<E> listIterator​(int index)  
      private ChunkList.ChunkListIterator locate​(int index)  
      private static java.lang.Object[] next​(java.lang.Object[] chunk)  
      private static int occupied​(java.lang.Object[] chunk)  
      private static java.lang.Object[] prev​(java.lang.Object[] chunk)  
      private static void setElement​(java.lang.Object[] chunk, int index, java.lang.Object element)  
      private static void setNext​(java.lang.Object[] chunk, java.lang.Object[] next)  
      private static void setOccupied​(java.lang.Object[] chunk, int size)  
      private static void setPrev​(java.lang.Object[] chunk, java.lang.Object[] prev)  
      int size()  
      • Methods inherited from class java.util.AbstractSequentialList

        addAll, get, iterator, remove, set
      • Methods inherited from class java.util.AbstractList

        equals, hashCode, indexOf, lastIndexOf, listIterator, removeRange, subList
      • Methods inherited from class java.util.AbstractCollection

        addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.Collection

        parallelStream, removeIf, stream, toArray
      • Methods inherited from interface java.lang.Iterable

      • Methods inherited from interface java.util.List

        addAll, contains, containsAll, isEmpty, remove, removeAll, replaceAll, retainAll, sort, spliterator, toArray, toArray
    • Field Detail

      • INTEGERS

        private static final java.lang.Integer[] INTEGERS
      • size

        private int size
      • first

        private java.lang.Object[] first
      • last

        private java.lang.Object[] last
    • Constructor Detail

      • ChunkList

        public ChunkList()
        Creates an empty ChunkList.
      • ChunkList

        public ChunkList​(java.util.Collection<E> collection)
        Creates a ChunkList whose contents are a given Collection.
    • Method Detail

      • isValid

        boolean isValid​(boolean fail)
        For debugging and testing.
      • listIterator

        public java.util.ListIterator<E> listIterator​(int index)
        Specified by:
        listIterator in interface java.util.List<E>
        Specified by:
        listIterator in class java.util.AbstractSequentialList<E>
      • size

        public int size()
        Specified by:
        size in interface java.util.Collection<E>
        Specified by:
        size in interface java.util.List<E>
        Specified by:
        size in class java.util.AbstractCollection<E>
      • clear

        public void clear()
        Specified by:
        clear in interface java.util.Collection<E>
        Specified by:
        clear in interface java.util.List<E>
        clear in class java.util.AbstractList<E>
      • add

        public boolean add​(E element)
        Specified by:
        add in interface java.util.Collection<E>
        Specified by:
        add in interface java.util.List<E>
        add in class java.util.AbstractList<E>
      • add

        public void add​(int index,
                        E element)
        Specified by:
        add in interface java.util.List<E>
        add in class java.util.AbstractSequentialList<E>
      • prev

        private static java.lang.Object[] prev​(java.lang.Object[] chunk)
      • setPrev

        private static void setPrev​(java.lang.Object[] chunk,
                                    java.lang.Object[] prev)
      • next

        private static java.lang.Object[] next​(java.lang.Object[] chunk)
      • setNext

        private static void setNext​(java.lang.Object[] chunk,
                                    java.lang.Object[] next)
      • occupied

        private static int occupied​(java.lang.Object[] chunk)
      • setOccupied

        private static void setOccupied​(java.lang.Object[] chunk,
                                        int size)
      • element

        private static java.lang.Object element​(java.lang.Object[] chunk,
                                                int index)
      • setElement

        private static void setElement​(java.lang.Object[] chunk,
                                       int index,
                                       java.lang.Object element)