Copyright 2008 - 2009 Tony Morris, Runar Bjarnason, Tom Adams, Brad Clow, Ricky Clarkson, Nick Partridge, Jason Zaugg

This software is released under an open source BSD licence.

fj.data.fingertrees
Class Deep<V,A>

java.lang.Object
  extended by fj.data.fingertrees.FingerTree<V,A>
      extended by fj.data.fingertrees.Deep<V,A>

public final class Deep<V,A>
extends FingerTree<V,A>

A finger tree with 1-4-digits on the left and right, and a finger tree of 2-3-nodes in the middle.


Method Summary
 FingerTree<V,A> append(FingerTree<V,A> t)
          Appends one finger tree to another.
 FingerTree<V,A> cons(A a)
          Adds the given element to this tree as the first element.
<B> B
foldLeft(F<B,F<A,B>> bff, B z)
          Folds the tree to the left with the given function and the given initial element.
<B> B
foldRight(F<A,F<B,B>> aff, B z)
          Folds the tree to the right with the given function and the given initial element.
 P2<Integer,A> lookup(F<V,Integer> o, int i)
           
<B> FingerTree<V,B>
map(F<A,B> abf, Measured<V,B> m)
          Maps the given function across this tree, measuring with the given Measured instance.
<B> B
match(F<Empty<V,A>,B> empty, F<Single<V,A>,B> single, F<Deep<V,A>,B> deep)
          Pattern matching on the tree.
 V measure()
          Returns the sum of the measurements of this tree's elements, according to the monoid.
 FingerTree<V,Node<V,A>> middle()
          Returns a finger tree of the inner nodes of this tree.
 Digit<V,A> prefix()
          Returns the first few elements of this tree.
 A reduceLeft(F<A,F<A,A>> aff)
          Folds the tree to the left with the given function.
 A reduceRight(F<A,F<A,A>> aff)
          Folds the tree to the right with the given function.
 FingerTree<V,A> snoc(A a)
          Adds the given element to this tree as the last element.
 Digit<V,A> suffix()
          Returns the last few elements of this tree.
 
Methods inherited from class fj.data.fingertrees.FingerTree
isEmpty, measured, measured, mkTree
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

prefix

public Digit<V,A> prefix()
Returns the first few elements of this tree.

Returns:
the first few elements of this tree.

middle

public FingerTree<V,Node<V,A>> middle()
Returns a finger tree of the inner nodes of this tree.

Returns:
a finger tree of the inner nodes of this tree.

suffix

public Digit<V,A> suffix()
Returns the last few elements of this tree.

Returns:
the last few elements of this tree.

foldRight

public <B> B foldRight(F<A,F<B,B>> aff,
                       B z)
Description copied from class: FingerTree
Folds the tree to the right with the given function and the given initial element.

Specified by:
foldRight in class FingerTree<V,A>
Parameters:
aff - A function with which to fold the tree.
z - An initial element to apply to the fold.
Returns:
A reduction of this tree by applying the given function, associating to the right.
See Also:
FingerTree.foldRight(fj.F, Object)

reduceRight

public A reduceRight(F<A,F<A,A>> aff)
Description copied from class: FingerTree
Folds the tree to the right with the given function.

Specified by:
reduceRight in class FingerTree<V,A>
Parameters:
aff - A function with which to fold the tree.
Returns:
A reduction of this tree by applying the given function, associating to the right.
See Also:
FingerTree.reduceRight(fj.F)

foldLeft

public <B> B foldLeft(F<B,F<A,B>> bff,
                      B z)
Description copied from class: FingerTree
Folds the tree to the left with the given function and the given initial element.

Specified by:
foldLeft in class FingerTree<V,A>
Parameters:
bff - A function with which to fold the tree.
z - An initial element to apply to the fold.
Returns:
A reduction of this tree by applying the given function, associating to the left.

reduceLeft

public A reduceLeft(F<A,F<A,A>> aff)
Description copied from class: FingerTree
Folds the tree to the left with the given function.

Specified by:
reduceLeft in class FingerTree<V,A>
Parameters:
aff - A function with which to fold the tree.
Returns:
A reduction of this tree by applying the given function, associating to the right.

map

public <B> FingerTree<V,B> map(F<A,B> abf,
                               Measured<V,B> m)
Description copied from class: FingerTree
Maps the given function across this tree, measuring with the given Measured instance.

Specified by:
map in class FingerTree<V,A>
Parameters:
abf - A function to map across the values of this tree.
m - A measuring with which to annotate the tree.
Returns:
A new tree with the same structure as this tree, with each element transformed by the given function, and nodes annotated according to the given measuring.

measure

public V measure()
Returns the sum of the measurements of this tree's elements, according to the monoid.

Specified by:
measure in class FingerTree<V,A>
Returns:
the sum of the measurements of this tree's elements, according to the monoid.

match

public <B> B match(F<Empty<V,A>,B> empty,
                   F<Single<V,A>,B> single,
                   F<Deep<V,A>,B> deep)
Pattern matching on the tree. Matches the function on the Deep tree.

Specified by:
match in class FingerTree<V,A>
Parameters:
empty - The function to apply to this empty tree.
single - A function to apply if this tree contains a single element.
deep - A function to apply if this tree contains more than one element.
Returns:
The result of the function that matches this tree structurally, applied to this tree.

cons

public FingerTree<V,A> cons(A a)
Description copied from class: FingerTree
Adds the given element to this tree as the first element.

Specified by:
cons in class FingerTree<V,A>
Parameters:
a - The element to add to the front of this tree.
Returns:
A new tree with the given element at the front.

snoc

public FingerTree<V,A> snoc(A a)
Description copied from class: FingerTree
Adds the given element to this tree as the last element.

Specified by:
snoc in class FingerTree<V,A>
Parameters:
a - The element to add to the end of this tree.
Returns:
A new tree with the given element at the end.

append

public FingerTree<V,A> append(FingerTree<V,A> t)
Description copied from class: FingerTree
Appends one finger tree to another.

Specified by:
append in class FingerTree<V,A>
Parameters:
t - A finger tree to append to this one.
Returns:
A new finger tree which is a concatenation of this tree and the given tree.

lookup

public P2<Integer,A> lookup(F<V,Integer> o,
                            int i)
Specified by:
lookup in class FingerTree<V,A>

Copyright 2008 - 2009 Tony Morris, Runar Bjarnason, Tom Adams, Brad Clow, Ricky Clarkson, Nick Partridge, Jason Zaugg

This software is released under an open source BSD licence.