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:
Iterable<T>
,Collection<T>
,List<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.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final int
private static final int
(package private) static final int
(package private) T[][]
(package private) int
private int
private T[]
private int
Fields inherited from class java.util.AbstractList
modCount
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
boolean
void
Quickly append all elements of another BlockList.void
Quickly append all elements from an array.void
clear()
get
(int index) iterator()
private static <T> T[]
newBlock()
private static <T> T[][]
newDirectory
(int size) remove
(int index) private void
int
size()
(package private) static final int
toBlockIndex
(int index) (package private) static final int
toDirectoryIndex
(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
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.util.List
addAll, contains, containsAll, isEmpty, remove, removeAll, replaceAll, retainAll, sort, spliterator, toArray, toArray
-
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
-
-
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 interfaceCollection<T>
- Specified by:
size
in interfaceList<T>
- Specified by:
size
in classAbstractCollection<T>
-
clear
public void clear()- Specified by:
clear
in interfaceCollection<T>
- Specified by:
clear
in interfaceList<T>
- Overrides:
clear
in classAbstractList<T>
-
get
-
set
-
addAll
Quickly append all elements of another BlockList.- Parameters:
src
- the list to copy elements from.
-
addAll
Quickly append all elements from an array.- Parameters:
src
- the source array.srcIdx
- first index to copy.srcCnt
- number of elements to copy.
-
add
- Specified by:
add
in interfaceCollection<T>
- Specified by:
add
in interfaceList<T>
- Overrides:
add
in classAbstractList<T>
-
add
-
remove
-
resetTailBlock
private void resetTailBlock() -
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()
-