Class BlockList<T>

java.lang.Object
java.util.AbstractCollection<T>
java.util.AbstractList<T>
org.eclipse.jgit.util.BlockList<T>
Type Parameters:
T - type of list element.
All Implemented Interfaces:
Iterable<T>, Collection<T>, List<T>

public class BlockList<T> extends AbstractList<T>
Random access list that allocates entries in blocks.

Unlike ArrayList, this type does not need to reallocate the internal array in order to expand the capacity of the list. Access to any element is constant time, but requires two array lookups instead of one.

To handle common usages, add(Object) and iterator() use internal code paths to amortize out the second array lookup, making addition and simple iteration closer to one array operation per element processed.

Similar to ArrayList, adding or removing from any position except the end of the list requires O(N) time to copy all elements between the modification point and the end of the list. Applications are strongly encouraged to not use this access pattern with this list implementation.

  • Field Details

    • BLOCK_BITS

      private static final int BLOCK_BITS
      See Also:
    • BLOCK_SIZE

      static final int BLOCK_SIZE
      See Also:
    • BLOCK_MASK

      private static final int BLOCK_MASK
      See Also:
    • directory

      T[][] directory
    • size

      int size
    • tailDirIdx

      private int tailDirIdx
    • tailBlkIdx

      private int tailBlkIdx
    • tailBlock

      private T[] tailBlock
  • Constructor Details

    • BlockList

      public BlockList()
      Initialize an empty list.
    • BlockList

      public BlockList(int capacity)
      Initialize an empty list with an expected capacity.
      Parameters:
      capacity - number of elements expected to be in the list.
  • Method Details

    • size

      public int size()
      Specified by:
      size in interface Collection<T>
      Specified by:
      size in interface List<T>
      Specified by:
      size in class AbstractCollection<T>
    • clear

      public void clear()
      Specified by:
      clear in interface Collection<T>
      Specified by:
      clear in interface List<T>
      Overrides:
      clear in class AbstractList<T>
    • get

      public T get(int index)
      Specified by:
      get in interface List<T>
      Specified by:
      get in class AbstractList<T>
    • set

      public T set(int index, T element)
      Specified by:
      set in interface List<T>
      Overrides:
      set in class AbstractList<T>
    • addAll

      public void addAll(BlockList<T> src)
      Quickly append all elements of another BlockList.
      Parameters:
      src - the list to copy elements from.
    • addAll

      public void addAll(T[] src, int srcIdx, int srcCnt)
      Quickly append all elements from an array.
      Parameters:
      src - the source array.
      srcIdx - first index to copy.
      srcCnt - number of elements to copy.
    • add

      public boolean add(T element)
      Specified by:
      add in interface Collection<T>
      Specified by:
      add in interface List<T>
      Overrides:
      add in class AbstractList<T>
    • add

      public void add(int index, T element)
      Specified by:
      add in interface List<T>
      Overrides:
      add in class AbstractList<T>
    • remove

      public T remove(int index)
      Specified by:
      remove in interface List<T>
      Overrides:
      remove in class AbstractList<T>
    • resetTailBlock

      private void resetTailBlock()
    • iterator

      public Iterator<T> iterator()
      Specified by:
      iterator in interface Collection<T>
      Specified by:
      iterator in interface Iterable<T>
      Specified by:
      iterator in interface List<T>
      Overrides:
      iterator in class AbstractList<T>
    • toDirectoryIndex

      static final int toDirectoryIndex(int index)
    • toBlockIndex

      static final int toBlockIndex(int index)
    • newDirectory

      private static <T> T[][] newDirectory(int size)
    • newBlock

      private static <T> T[] newBlock()