sealed abstract class FingerTree[V, A] extends AnyRef
Finger trees with leaves of type A and Nodes that are annotated with type V.
Finger Trees provide a base for implementations of various collection types, as described in "Finger trees: a simple general-purpose data structure", by Ralf Hinze and Ross Paterson. A gentle introduction is presented in the blog post "Monoids and Finger Trees" by Heinrich Apfelmus.
This is done by choosing a suitable type to annotate the nodes. For example, a binary tree can be implemented by annotating each node with the size of its subtree, while a priority queue can be implemented by labelling the nodes by the minimum priority of its children.
The operations on FingerTree enforce the constraint measured (in the form of a Reducer instance).
Finger Trees have excellent (amortized) asymptotic performance:
- Access to the first and last elements is
O(1)
- Appending/prepending a single value is
O(1)
- Concatenating two trees is
(O lg min(l1, l2))
wherel1
andl2
are their sizes - Random access to an element at
n
isO(lg min(n, l - n))
, wherel
is the size of the tree. - Constructing a tree with n copies of a value is O(lg n).
- V
The type of the annotations of the nodes (the measure)
- A
The type of the elements stored at the leaves
- Alphabetic
- By Inheritance
- FingerTree
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Abstract Value Members
- abstract def fold[B](empty: => B, single: (V, A) => B, deep: (V, Finger[V, A], => FingerTree[V, Node[V, A]], Finger[V, A]) => B): B
Fold over the structure of the tree.
Fold over the structure of the tree. The given functions correspond to the three possible variations of the finger tree.
- empty
value to return if the tree is empty
- single
if the tree contains a single element, convert the measure and this element to a
B
- deep
otherwise, convert the measure, the two fingers, and the sub tree to a
B
.
Concrete Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##: Int
- Definition Classes
- AnyRef → Any
- def +:(a: A): FingerTree[V, A]
Prepends an element to the left of the tree.
Prepends an element to the left of the tree. O(1).
- def :+(a: => A): FingerTree[V, A]
Appends an element to the right of the tree.
Appends an element to the right of the tree. O(1).
- def :-|(a: => A): FingerTree[V, A]
Replace the last element of the tree with the given value.
Replace the last element of the tree with the given value. O(1)
- def <++>(right: => FingerTree[V, A]): FingerTree[V, A]
Appends the given finger tree to the right of this tree.
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- def add1(n: A, right: => ATree): ATree
- def add2(n1t: => A, n2t: => A, right: => ATree): ATree
- def add3(n1t: => A, n2t: => A, n3t: => A, right: => ATree): ATree
- def add4(n1t: => A, n2t: => A, n3t: => A, n4t: => A, right: => ATree): ATree
- def addDigits0(m1: NodeTree, dig1: AFinger, dig2: AFinger, m2: => NodeTree): NodeTree
- def addDigits1(m1: NodeTree, d1: AFinger, xt: => A, d2: AFinger, m2t: => NodeTree): NodeTree
- def addDigits2(m1: NodeTree, d1: AFinger, xt: => A, yt: => A, d2: AFinger, m2t: => NodeTree): NodeTree
- def addDigits3(m1: NodeTree, d1: AFinger, xt: => A, yt: => A, zt: => A, d2: AFinger, m2t: => NodeTree): NodeTree
- def addDigits4(m1: NodeTree, d1: AFinger, xt: => A, yt: => A, zt: => A, wt: => A, d2: AFinger, m2t: => NodeTree): NodeTree
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native()
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable])
- def foldLeft[B](b: B)(f: (B, A) => B): B
- def foldMap[B](f: (A) => B)(implicit s: Monoid[B]): B
- def foldRight[B](z: => B)(f: (A, => B) => B): B
- def foreach(f: (A) => Unit): Unit
Execute the provided side effect for each element in the tree.
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- def head: A
Selects the first element in the tree.
Selects the first element in the tree.
- Exceptions thrown
if
the tree is empty
- def init: FingerTree[V, A]
Selects a subtree containing all elements except the last
Selects a subtree containing all elements except the last
- Exceptions thrown
if
the tree is empty
- def isEmpty: Boolean
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- def iterator: Iterator[A]
An iterator that visits each element in the tree.
- def last: A
Selects the last element in the tree.
Selects the last element in the tree.
- Exceptions thrown
if
the tree is empty
- def map[B, V2](f: (A) => B)(implicit r: Reducer[B, V2]): FingerTree[V2, B]
Maps the given function across the tree, annotating nodes in the resulting tree according to the provided
Reducer
. - def measure: Maybe[V]
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- def reduceTo[M](implicit arg0: Reducer[A, M], arg1: Monoid[M]): M
Convert the leaves of the tree to an
M
- def reverseIterator: Iterator[A]
An iterator that visits each element in the tree in reverse order.
- def split(pred: (V) => Boolean): (FingerTree[V, A], FingerTree[V, A])
Splits this tree into a pair of subtrees at the point where the given predicate, based on the measure, changes from
false
totrue
.Splits this tree into a pair of subtrees at the point where the given predicate, based on the measure, changes from
false
totrue
. O(log(min(i,n-i)))- pred
predicate on node measures. Must be a semigroup homomorphism from the semigroup
V
of node measures to the semigroup ofBoolean
s with||
as the semigroup operation. Namely, it must hold thatpred(v1 |+| v2) = pred(v1) || pred(v2)
.- returns
(as, bs)
, whereas
: the subtree containing elements before the point wherepred
first holdsbs
: the subtree containing elements at and after the point wherepred
first holds. Empty ifpred
never holds.
- def split1(pred: (V) => Boolean): (FingerTree[V, A], A, FingerTree[V, A])
Like
split
, but returns the element wherepred
first holds separatelyLike
split
, but returns the element wherepred
first holds separately- Exceptions thrown
if
the tree is empty.
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def tail: FingerTree[V, A]
Selects a subtree containing all elements except the first
Selects a subtree containing all elements except the first
- Exceptions thrown
if
the tree is empty
- def to[F[_]](implicit R: Reducer[A, F[A]], M: Monoid[F[A]]): F[A]
Convert the leaves of the tree to an
F[A]
- def toIList: IList[A]
Convert the leaves of the tree to a
scalaz.IList
- def toLazyList: LazyList[A]
Convert the leaves of the tree to a
scala.LazyList
- def toList: List[A]
Convert the leaves of the tree to a
scala.List
- def toString(): String
Convert the tree to a
String
.Convert the tree to a
String
. Unsafe: this usesAny#toString
for typesV
andA
- Definition Classes
- FingerTree → AnyRef → Any
- def traverseTree[F[_], V2, B](f: (A) => F[B])(implicit ms: Reducer[B, V2], F: Applicative[F]): F[FingerTree[V2, B]]
Like traverse, but with a more constraint type: we need the additional measure to construct the new tree.
- def viewl: ViewL[[β$0$]FingerTree[V, β$0$], A]
- def viewr: ViewR[[β$5$]FingerTree[V, β$5$], A]
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
- def |-:(a: A): FingerTree[V, A]
Replace the first element of the tree with the given value.
Replace the first element of the tree with the given value. O(1)