A tree relation is a binary relation on tree nodes with an extra property
that the image
operation throws a NodeNotInTreeException
exception if
it is applied to a node that is not in this tree.
Relation factory for tree relations.
A version of bottomup
that doesn't traverse bridges.
The basic relation between a node and its children.
The basic relation between a node and its children. All of the other relations are derived from this one. This relation preserves order in the sense that the graph of this relation records the children of a particular node in the order they appear in the tree.
The graph of the child relation for this tree.
A version of everywherebu
that doesn't traverse bridges.
A relation that relates a node to its first child.
Return the index of t
in the children of t's
parent node.
Return the index of t
in the children of t's
parent node.
Counts from zero.
Return whether or not t
is a first child.
Return whether or not t
is a last child.
Return whether or not t
is the root of this tree.
A relation that relates a node to its last child.
A relation that relates a node to its next sibling.
A relation that relates a node to its next sibling. Inverse of
the prev
relation.
The nodes that occur in this tree.
A relation that relates a node to its parent.
A relation that relates a node to its parent. Inverse of the
child
relation.
A relation that relates a node to its previous sibling.
A relation that relates a node to its previous sibling. Inverse
of the next
relation.
The root node of the tree.
The root node of the tree. The root node will be different from the
original root if any nodes in the original tree are shared, since
they will be cloned as necessary to yield a proper tree structure.
If there is no sharing then root
will be same as originalRoot
.
Bridges to other structures will not be traversed.
A relation that relates a node to all of its siblings.
If the tree contains node u
return v
, otherwise throw a
NodeNotInTreeException
.
Relational representations of trees built out of hierarchical
Product
instances. Typically, the nodes are instances of case classes.The type
T
is the common base type of the tree nodes. The typeR
is a sub-type ofT
that is the type of the root node.The
originalRoot
value should be the root of a finite, acyclic structure that contains onlyProduct
instances of typeT
(unless they are skipped, see below). If the structure reachable fromoriginalRoot
is actually a tree (i.e., contains no shared nodes) then the fieldroot
will be the same asoriginalRoot
.On the other hand, if the structure contains shared nodes, then
root
will be the root of a new structure which duplicates the original structure but removes the sharing. In other words, shared nodes will be copied.The
child
relation of a tree is defined to skip certain nodes. Specifically, if a node of typeT
is wrapped in aSome
of an option, aLeft
orRight
of anEither
, a tuple up to size four, or aTraversableOnce
, then those wrappers are ignored. E.g., ift1
isSome (t2)
where botht1
andt2
are of typeT
, thent1
will bet2
's parent, not theSome
value.Thanks to Len Hamey for the idea to use lazy cloning to restore the tree structure instead of requiring that the input trees contain no sharing.