A bridge node in a tree structure which connects to another structure.
Exception thrown if a tree relation operation tries to use a node that is not in the tree to which the relation applies.
Exception thrown if a tree relation operation tries to use a node that
is not in the tree to which the relation applies. t
is the node that
was found not to be in the tree.
For the time-being, the exception does not indicate which tree is involved because it's not clear how to identify the tree briefly in a short message. The stack trace that accompanies the exception should be sufficient.
A binary relation between values of type T
and values of type U
.
A binary relation between values of type T
and values of type U
.
Constructed from memoised caches that map T
values to their image
and vice versa.
Exception thrown if CheckTree
is specified as a tree's shape but the
provided structure is not a tree.
Exception thrown if CheckTree
is specified as a tree's shape but the
provided structure is not a tree. msg
describes the reason(s) why the
structure is not a tree by listing the nodes that have more than one
parent.
Relational representations of trees built out of hierarchical Product
instances.
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 type R
is a
sub-type of T
that is the type of the root node.
The originalRoot
value should be the root of a finite, acyclic structure
that contains only Product
instances of type T
(unless they are skipped,
see below).
The shape
argument governs how the structure referred to by originalRoot
is treated. If shape
is LeaveAlone
(the default) then the structure is
used without change. If shape
is CheckTree
then a check is run before
the structure is used to make sure that it is a tree (i.e., no node sharing
nor cycles). A runtime error occurs if this is not the case. If shape
is
EnsureTree
then shared parts of the structure are cloned to ensure that
it is a tree before it is used.
If you are confident that your structure is a tree (e.g., it comes from a
parser) then the default shape should be fine. If you prefer a bit more
safety, then use CheckTree
so that a non-tree structure cannot be missed.
Finally, use EnsureTree
if you know that your structure may contain
sharing (e.g., it is produced by a term rewriting process).
The child
relation of a tree is defined to skip certain nodes.
Specifically, if a node of type T
is wrapped in a Some
of an option,
a Left
or Right
of an Either
, a tuple up to size four, or a
TraversableOnce
, then those wrappers are ignored. E.g., if t1
is Some (t2)
where both t1
and t2
are of type T
, then t1
will be t2
's parent, not the Some
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.
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.
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. T
is the type of the
tree nodes.
Tree properties
The incoming structure should be a tree (i.e., no sharing nor cycles) but a runtime check should be performed to make sure.
The incoming structure may not be a tree (e.g., may contain sharing) and shared parts should be cloned to make it a tree before any further processing is performed.
The incoming structure has an acceptable shape and should be left alone by the tree processing.
Support for binary relations.
Support for tree relations.
A bridge node in a tree structure which connects to another structure. Bridges are not traversed when determining the tree structure.