scalaz

FingerTree

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 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:

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

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

Finger trees: a simple general-purpose data structure

Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. FingerTree
  2. AnyRef
  3. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Instance Constructors

  1. new FingerTree()(implicit measurer: Reducer[A, V])

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: AnyRef): Boolean

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  3. final def ##(): Int

    Definition Classes
    AnyRef → Any
  4. 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).

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

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

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

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

  8. final def ==(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  9. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  10. def add1(n: A, right: ⇒ ATree): ATree

  11. def add2(n1: ⇒ A, n2: ⇒ A, right: ⇒ ATree): ATree

  12. def add3(n1: ⇒ A, n2: ⇒ A, n3: ⇒ A, right: ⇒ ATree): ATree

  13. def add4(n1: ⇒ A, n2: ⇒ A, n3: ⇒ A, n4: ⇒ A, right: ⇒ ATree): ATree

  14. def addDigits0(m1: ⇒ NodeTree, dig1: ⇒ AFinger, dig2: ⇒ AFinger, m2: ⇒ NodeTree): NodeTree

  15. def addDigits1(m1: ⇒ NodeTree, d1: ⇒ AFinger, x: ⇒ A, d2: ⇒ AFinger, m2: ⇒ NodeTree): NodeTree

  16. def addDigits2(m1: ⇒ NodeTree, d1: ⇒ AFinger, x: ⇒ A, y: ⇒ A, d2: ⇒ AFinger, m2: ⇒ NodeTree): NodeTree

  17. def addDigits3(m1: ⇒ NodeTree, d1: ⇒ AFinger, x: ⇒ A, y: ⇒ A, z: ⇒ A, d2: ⇒ AFinger, m2: ⇒ NodeTree): NodeTree

  18. def addDigits4(m1: ⇒ NodeTree, d1: ⇒ AFinger, x: ⇒ A, y: ⇒ A, z: ⇒ A, w: ⇒ A, d2: ⇒ AFinger, m2: ⇒ NodeTree): NodeTree

  19. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  20. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws()
  21. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  22. def equals(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  23. def finalize(): Unit

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws()
  24. def foldLeft[B](b: B)(f: (B, A) ⇒ B): B

  25. def foldMap[B](f: (A) ⇒ B)(implicit s: Monoid[B]): B

  26. def foldRight[B](z: ⇒ B)(f: (A, ⇒ B) ⇒ B): B

  27. def foreach(f: (A) ⇒ Unit): Unit

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

  28. final def getClass(): Class[_]

    Definition Classes
    AnyRef → Any
  29. def hashCode(): Int

    Definition Classes
    AnyRef → Any
  30. def head: A

    Selects the first element in the tree.

    Selects the first element in the tree.

    Exceptions thrown
    if

    the tree is empty

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

  32. def isEmpty: Boolean

  33. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  34. def iterator: Iterator[A]

    An iterator that visits each element in the tree.

  35. def last: A

    Selects the last element in the tree.

    Selects the last element in the tree.

    Exceptions thrown
    if

    the tree is empty

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

  37. def measure: V

  38. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  39. final def notify(): Unit

    Definition Classes
    AnyRef
  40. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  41. def reverseIterator: Iterator[A]

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

  42. 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 true to false.

    Splits this tree into a pair of subtrees at the point where the given predicate, based on the measure, changes from true to false. O(log(min(i,n-i)))

    returns

    (as, bs) as: the subtree containing elements before the point where pred first holds fs the subtree containing element at and after the point where pred first holds. Empty if pred never holds.

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

  44. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  45. 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

  46. def toList: List[A]

    Convert the leaves of the tree to a scala.List

  47. def toStream: Stream[A]

    Convert the leaves of the tree to a scala.Stream

  48. 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
  49. 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.

  50. def viewl: ViewL[[α]FingerTree[V, α], A]

  51. def viewr: ViewR[[α]FingerTree[V, α], A]

  52. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws()
  53. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws()
  54. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws()
  55. 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