Package org.eclipse.jgit.util
Class BlockList<T>
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractList<T>
-
- org.eclipse.jgit.util.BlockList<T>
-
- Type Parameters:
T- type of list element.
- All Implemented Interfaces:
java.lang.Iterable<T>,java.util.Collection<T>,java.util.List<T>
public class BlockList<T> extends java.util.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)anditerator()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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classBlockList.MyIterator
-
Field Summary
Fields Modifier and Type Field Description private static intBLOCK_BITSprivate static intBLOCK_MASK(package private) static intBLOCK_SIZE(package private) T[][]directory(package private) intsizeprivate inttailBlkIdxprivate T[]tailBlockprivate inttailDirIdx
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(int index, T element)booleanadd(T element)voidaddAll(BlockList<T> src)Quickly append all elements of another BlockList.voidaddAll(T[] src, int srcIdx, int srcCnt)Quickly append all elements from an array.voidclear()Tget(int index)java.util.Iterator<T>iterator()private static <T> T[]newBlock()private static <T> T[][]newDirectory(int size)Tremove(int index)private voidresetTailBlock()Tset(int index, T element)intsize()(package private) static inttoBlockIndex(int index)(package private) static inttoDirectoryIndex(int index)-
Methods inherited from class java.util.AbstractList
addAll, equals, hashCode, indexOf, lastIndexOf, listIterator, listIterator, removeRange, subList
-
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
-
-
-
-
Field Detail
-
BLOCK_BITS
private static final int BLOCK_BITS
- See Also:
- Constant Field Values
-
BLOCK_SIZE
static final int BLOCK_SIZE
- See Also:
- Constant Field Values
-
BLOCK_MASK
private static final int BLOCK_MASK
- See Also:
- Constant Field Values
-
directory
T[][] directory
-
size
int size
-
tailDirIdx
private int tailDirIdx
-
tailBlkIdx
private int tailBlkIdx
-
tailBlock
private T[] tailBlock
-
-
Method Detail
-
size
public int size()
-
clear
public void clear()
-
get
public T get(int index)
-
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)
-
add
public void add(int index, T element)
-
remove
public T remove(int index)
-
resetTailBlock
private void resetTailBlock()
-
iterator
public java.util.Iterator<T> iterator()
-
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()
-
-