Class Vector<E>
- java.lang.Object
-
- com.github.andrewoma.dexx.collection.internal.base.AbstractTraversable<E>
-
- com.github.andrewoma.dexx.collection.internal.base.AbstractIterable<E>
-
- com.github.andrewoma.dexx.collection.internal.base.AbstractList<E>
-
- com.github.andrewoma.dexx.collection.internal.base.AbstractIndexedList<E>
-
- com.github.andrewoma.dexx.collection.Vector<E>
-
- All Implemented Interfaces:
IndexedList<E>
,Iterable<E>
,List<E>
,Traversable<E>
,java.lang.Iterable<E>
public class Vector<E> extends AbstractIndexedList<E>
Vector is a general-purpose, immutable data structure.It provides random access and updates in effectively constant time, as well as very fast append and prepend.
It is backed by a little endian bit-mapped vector trie with a branching factor of 32. Locality is very good, but not contiguous, which is good for very large sequences.
See Scala's documentation for more information on the implementation.
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
dirty
private static Vector
EMPTY
private int
endIndex
private int
focus
protected VectorPointer<E>
pointer
private int
startIndex
-
Constructor Summary
Constructors Constructor Description Vector(int startIndex, int endIndex, int focus)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description @NotNull Vector<E>
append(E value)
Returns a list with the specified element appended to the bottom of the list.private int
checkRangeConvert(int index)
private void
cleanLeftEdge(int cutIndex)
private void
cleanRightEdge(int cutIndex)
private java.lang.Object[]
copyLeft(java.lang.Object[] array, int right)
private java.lang.Object[]
copyRight(java.lang.Object[] array, int left)
@NotNull Vector<E>
drop(int n)
Returns a list containing all elements in this list, excluding the firstnumber
of elements.private Vector<E>
dropBack0(int cutIndex)
private Vector<E>
dropFront0(int cutIndex)
static <E> @NotNull Vector<E>
empty()
static <E> @NotNull BuilderFactory<E,Vector<E>>
factory()
E
first()
Returns first element in the list ornull
if the list is empty.E
get(int index)
Returns the element at the specified index in this list (zero-based).private void
gotoFreshPosWritable(int oldIndex, int newIndex, int xor)
private void
gotoPosWritable(int oldIndex, int newIndex, int xor)
private void
initIterator(VectorIterator<E> s)
boolean
isEmpty()
Returns true if this collection is empty.@NotNull java.util.Iterator<E>
iterator()
E
last()
Returns last element in the list ornull
if the list is empty.private void
preClean(int depth)
@NotNull Vector<E>
prepend(E value)
Returns a list with the specified element prepended to the top of the list.@NotNull Vector<E>
range(int from, boolean fromInclusive, int to, boolean toInclusive)
Returns a list containing a contiguous range of elements from this list.private int
requiredDepth(int xor)
@NotNull Vector<E>
set(int index, E elem)
Returns a list with the element set to the value specified at the index (zero-based).private void
shiftTopLevel(int oldLeft, int newLeft)
int
size()
Returns the size of the collection.private @NotNull Vector<E>
slice(int from, int until)
protected @NotNull Pair<Vector<E>,Vector<E>>
splitAt(int n)
@NotNull Vector<E>
tail()
Returns a list containing all elements in the list, excluding the first element.@NotNull Vector<E>
take(int n)
Returns a list containing the firstnumber
of elements from this list.private void
zeroLeft(java.lang.Object[] array, int index)
private void
zeroRight(java.lang.Object[] array, int index)
-
Methods inherited from class com.github.andrewoma.dexx.collection.internal.base.AbstractList
asList, equals, hashCode, indexOf, lastIndexOf
-
Methods inherited from class com.github.andrewoma.dexx.collection.internal.base.AbstractIterable
forEach
-
Methods inherited from class com.github.andrewoma.dexx.collection.internal.base.AbstractTraversable
makeString, makeString, to, toArray, toArray, toIndexedList, toSet, toSortedSet, toString
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.github.andrewoma.dexx.collection.List
asList, indexOf, lastIndexOf
-
Methods inherited from interface com.github.andrewoma.dexx.collection.Traversable
forEach, makeString, makeString, to, toArray, toArray, toIndexedList, toSet, toSortedSet
-
-
-
-
Field Detail
-
EMPTY
private static final Vector EMPTY
-
pointer
protected final VectorPointer<E> pointer
-
startIndex
private final int startIndex
-
endIndex
private final int endIndex
-
focus
private final int focus
-
dirty
private boolean dirty
-
-
Method Detail
-
factory
@NotNull public static <E> @NotNull BuilderFactory<E,Vector<E>> factory()
-
empty
@NotNull public static <E> @NotNull Vector<E> empty()
-
size
public int size()
Description copied from interface:Traversable
Returns the size of the collection.Warning: infinite collections are possible, as are collections that require traversal to calculate the size.
- Specified by:
size
in interfaceTraversable<E>
- Overrides:
size
in classAbstractTraversable<E>
-
initIterator
private void initIterator(VectorIterator<E> s)
-
iterator
@NotNull public @NotNull java.util.Iterator<E> iterator()
-
get
public E get(int index)
Description copied from interface:List
Returns the element at the specified index in this list (zero-based).
-
checkRangeConvert
private int checkRangeConvert(int index)
-
take
@NotNull public @NotNull Vector<E> take(int n)
Description copied from interface:List
Returns a list containing the firstnumber
of elements from this list.
-
drop
@NotNull public @NotNull Vector<E> drop(int n)
Description copied from interface:List
Returns a list containing all elements in this list, excluding the firstnumber
of elements.
-
isEmpty
public boolean isEmpty()
Description copied from interface:Traversable
Returns true if this collection is empty.- Specified by:
isEmpty
in interfaceTraversable<E>
- Overrides:
isEmpty
in classAbstractTraversable<E>
-
first
@Nullable public E first()
Description copied from interface:List
Returns first element in the list ornull
if the list is empty.
-
tail
@NotNull public @NotNull Vector<E> tail()
Description copied from interface:List
Returns a list containing all elements in the list, excluding the first element. An empty list is returned if the list is empty.
-
last
@Nullable public E last()
Description copied from interface:List
Returns last element in the list ornull
if the list is empty.
-
range
@NotNull public @NotNull Vector<E> range(int from, boolean fromInclusive, int to, boolean toInclusive)
Description copied from interface:List
Returns a list containing a contiguous range of elements from this list.- Parameters:
from
- starting index for the range (zero-based)fromInclusive
- if true, the element at thefrom
index will be includedto
- end index for the range (zero-based)toInclusive
- if true, the element at theto
index will be included
-
set
@NotNull public @NotNull Vector<E> set(int index, E elem)
Description copied from interface:List
Returns a list with the element set to the value specified at the index (zero-based).
-
gotoPosWritable
private void gotoPosWritable(int oldIndex, int newIndex, int xor)
-
gotoFreshPosWritable
private void gotoFreshPosWritable(int oldIndex, int newIndex, int xor)
-
prepend
@NotNull public @NotNull Vector<E> prepend(E value)
Description copied from interface:List
Returns a list with the specified element prepended to the top of the list.
-
append
@NotNull public @NotNull Vector<E> append(E value)
Description copied from interface:List
Returns a list with the specified element appended to the bottom of the list.
-
shiftTopLevel
private void shiftTopLevel(int oldLeft, int newLeft)
-
zeroLeft
private void zeroLeft(java.lang.Object[] array, int index)
-
zeroRight
private void zeroRight(java.lang.Object[] array, int index)
-
copyLeft
private java.lang.Object[] copyLeft(java.lang.Object[] array, int right)
-
copyRight
private java.lang.Object[] copyRight(java.lang.Object[] array, int left)
-
preClean
private void preClean(int depth)
-
cleanLeftEdge
private void cleanLeftEdge(int cutIndex)
-
cleanRightEdge
private void cleanRightEdge(int cutIndex)
-
requiredDepth
private int requiredDepth(int xor)
-
-