Packages

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)) where l1 and l2 are their sizes
  • Random access to an element at n is O(lg min(n, l - n)), where l 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

Source
FingerTree.scala
See also

Finger trees: a simple general-purpose data structure

http://apfelmus.nfshost.com/articles/monoid-fingertree.html

Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. FingerTree
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Abstract Value Members

  1. abstract def fold[B](empty: (V) ⇒ 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

    if the tree is empty, convert the measure to a B

    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

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. 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).

  4. 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).

  5. 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)

  6. def <++>(right: ⇒ FingerTree[V, A]): FingerTree[V, A]

    Appends the given finger tree to the right of this tree.

  7. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  8. def add1(n: A, right: ⇒ ATree): ATree
  9. def add2(n1t: ⇒ A, n2t: ⇒ A, right: ⇒ ATree): ATree
  10. def add3(n1t: ⇒ A, n2t: ⇒ A, n3t: ⇒ A, right: ⇒ ATree): ATree
  11. def add4(n1t: ⇒ A, n2t: ⇒ A, n3t: ⇒ A, n4t: ⇒ A, right: ⇒ ATree): ATree
  12. def addDigits0(m1: NodeTree, dig1: AFinger, dig2: AFinger, m2: ⇒ NodeTree): NodeTree
  13. def addDigits1(m1: NodeTree, d1: AFinger, xt: ⇒ A, d2: AFinger, m2t: ⇒ NodeTree): NodeTree
  14. def addDigits2(m1: NodeTree, d1: AFinger, xt: ⇒ A, yt: ⇒ A, d2: AFinger, m2t: ⇒ NodeTree): NodeTree
  15. def addDigits3(m1: NodeTree, d1: AFinger, xt: ⇒ A, yt: ⇒ A, zt: ⇒ A, d2: AFinger, m2t: ⇒ NodeTree): NodeTree
  16. def addDigits4(m1: NodeTree, d1: AFinger, xt: ⇒ A, yt: ⇒ A, zt: ⇒ A, wt: ⇒ A, d2: AFinger, m2t: ⇒ NodeTree): NodeTree
  17. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  18. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... ) @native()
  19. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  20. def equals(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  21. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  22. def foldLeft[B](b: B)(f: (B, A) ⇒ B): B
  23. def foldMap[B](f: (A) ⇒ B)(implicit s: Monoid[B]): B
  24. def foldRight[B](z: ⇒ B)(f: (A, ⇒ B) ⇒ B): B
  25. def foreach(f: (A) ⇒ Unit): Unit

    Execute the provided side effect for each element in the tree.

  26. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  27. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  28. def head: A

    Selects the first element in the tree.

    Selects the first element in the tree.

    Exceptions thrown

    if the tree is empty

  29. 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

  30. def isEmpty: Boolean
  31. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  32. def iterator: Iterator[A]

    An iterator that visits each element in the tree.

  33. def last: A

    Selects the last element in the tree.

    Selects the last element in the tree.

    Exceptions thrown

    if the tree is empty

  34. def map[B, V2](f: (A) ⇒ B)(implicit m: Reducer[B, V2]): FingerTree[V2, B]

    Maps the given function across the tree, annotating nodes in the resulting tree according to the provided Reducer.

  35. def measure: V
  36. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  37. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  38. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  39. def reverseIterator: Iterator[A]

    An iterator that visits each element in the tree in reverse order.

  40. 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 to true.

    Splits this tree into a pair of subtrees at the point where the given predicate, based on the measure, changes from false to true. 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 of Booleans with || as the semigroup operation. Namely, it must hold that pred(v1 |+| v2) = pred(v1) || pred(v2).

    returns

    (as, bs), where

    • as: the subtree containing elements before the point where pred first holds
    • bs: the subtree containing elements at and after the point where pred first holds. Empty if pred never holds.
  41. def split1(pred: (V) ⇒ Boolean): (FingerTree[V, A], A, FingerTree[V, A])

    Like split, but returns the element where pred first holds separately

    Like split, but returns the element where pred first holds separately

    Exceptions thrown

    if the tree is empty.

  42. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  43. 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

  44. def toList: List[A]

    Convert the leaves of the tree to a scala.List

  45. def toStream: Stream[A]

    Convert the leaves of the tree to a scala.Stream

  46. def toString(): String

    Convert the tree to a String.

    Convert the tree to a String. Unsafe: this uses Any#toString for types V and A

    Definition Classes
    FingerTree → AnyRef → Any
  47. 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.

  48. def viewl: ViewL[[β$0$]FingerTree[V, β$0$], A]
  49. def viewr: ViewR[[β$5$]FingerTree[V, β$5$], A]
  50. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  51. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  52. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... ) @native()
  53. 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)

Inherited from AnyRef

Inherited from Any

Ungrouped