Package org.basex.query.util.fingertree
Class FingerTree<N,E>
java.lang.Object
org.basex.query.util.fingertree.FingerTree<N,E>
- Type Parameters:
N- node typeE- element type
- All Implemented Interfaces:
Iterable<E>
A node of a FingerTree.
- Author:
- BaseX Team 2005-21, BSD License, Leo Woerteler
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract longChecks that this tree does not violate any invariants.abstract FingerTree<N,E> Concatenates this finger tree with the given one.abstract FingerTree<N,E> Adds an element to the front of this tree.static <E> FingerTree<E,E> empty()Returns the empty finger tree.final Eget(long index) Returns the element at the given position in this tree.head()Returns the first element of this tree.abstract FingerTree<N,E> init()Returns this tree removing the last element.abstract FingerTree<N,E> insert(long pos, E val, QueryContext qc) Inserts the given value at the given position into this tree.final booleanisEmpty()Checks if this node is empty.final ListIterator<E>iterator()last()Returns the last element of this tree.final ListIterator<E>listIterator(long start) Creates aListIteratorover the elements in this tree.remove(long pos, QueryContext qc) Removes an element from this tree.abstract FingerTree<N,E> replaceHead(Node<N, E> head) Replaces the first node in this tree.abstract FingerTree<N,E> replaceLast(Node<N, E> last) Replaces the last node in this tree.abstract FingerTree<N,E> reverse(QueryContext qc) Creates a reversed version of this tree.abstract FingerTree<N,E> Replaces the element at the given position in this tree.static <E> FingerTree<E,E> Creates a singleton finger tree containing the given leaf node.abstract longsize()The size of this tree.slice(long pos, long len) Extracts a slice from this tree containing thelenelements starting with that at positionpos.abstract FingerTree<N,E> Adds an element to the end of this tree.abstract FingerTree<N,E> tail()Returns this tree removing the first element.final StringtoString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
FingerTree
public FingerTree()
-
-
Method Details
-
empty
Returns the empty finger tree.- Type Parameters:
E- element type- Returns:
- empty finger tree
-
singleton
Creates a singleton finger tree containing the given leaf node.- Type Parameters:
E- element type- Parameters:
leaf- the contained leaf- Returns:
- the singleton finger tree
-
isEmpty
public final boolean isEmpty()Checks if this node is empty.- Returns:
trueif the node is empty,falseotherwise
-
get
Returns the element at the given position in this tree.- Parameters:
index- index of the element- Returns:
- the element
-
set
Replaces the element at the given position in this tree.- Parameters:
pos- positionval- element- Returns:
- resulting tree
-
size
public abstract long size()The size of this tree.- Returns:
- number of elements in this tree
-
cons
Adds an element to the front of this tree.- Parameters:
fst- new first element- Returns:
- updated tree
-
snoc
Adds an element to the end of this tree.- Parameters:
lst- new last element- Returns:
- updated tree
-
head
Returns the first element of this tree.- Returns:
- first element
- Throws:
NoSuchElementException- if the tree is empty
-
tail
Returns this tree removing the first element.- Returns:
- updated tree
-
last
Returns the last element of this tree.- Returns:
- last element
- Throws:
NoSuchElementException- if the tree is empty
-
init
Returns this tree removing the last element.- Returns:
- updated tree
-
concat
Concatenates this finger tree with the given one.- Parameters:
mid- nodes between the two treessize- sum of the sizes of all nodes in the middle arrayother- the other tree- Returns:
- concatenation of both trees
-
reverse
Creates a reversed version of this tree.- Parameters:
qc- query context- Returns:
- reversed tree
-
insert
Inserts the given value at the given position into this tree.- Parameters:
pos- position to insert atval- value to insertqc- query context- Returns:
- resulting tree
-
remove
Removes an element from this tree.- Parameters:
pos- position of the element to removeqc- query context- Returns:
- resulting (potentially partial) tree
- Throws:
AssertionError- if this tree is empty
-
slice
Extracts a slice from this tree containing thelenelements starting with that at positionpos.- Parameters:
pos- position of the first elementlen- number of elements- Returns:
- resulting slice
-
replaceHead
Replaces the first node in this tree.- Parameters:
head- new first node- Returns:
- resulting tree
-
replaceLast
Replaces the last node in this tree.- Parameters:
last- new last node- Returns:
- resulting tree
-
toString
-
checkInvariants
public abstract long checkInvariants()Checks that this tree does not violate any invariants.- Returns:
- number of elements in this tree
- Throws:
AssertionError- if any invariant was violated
-
listIterator
Creates aListIteratorover the elements in this tree.- Parameters:
start- starting position (i.e. the position initially returned byListIterator.nextIndex())- Returns:
- the list iterator
-
iterator
-