Perform a reordering.
Perform a reordering.
This method takes two nodes (n1
and n2
), as well as two
functions:
f
: function from node to identifying annotationg
: function from two nodes to a combined resultThe f
function is used in cases where sorting or weighting is
necessary (in those cases A will be a weight or similar). The g
function is used to recurse on the result -- i.e. the possibly
reordered nodes n1
and n2
will be passed to g
after the
reordering occurs.
Seed a reorder instance with a stable identifier.
Seed a reorder instance with a stable identifier.
This ensures that reorders which are non-deterministic in general (e.g. shuffled) will produce the same reordering for the same seed across many traversals.
On deterministic reorders this method is a noop.
Simple data type that provides rules to order nodes during traversal.
In some cases subtypes of Reorder will also wraps RNG state, for instances that need to randomly select instances. Thus, Reorder is not guaranteed to be referentially-transparent. Fresh instances should be used with each traversal.
Reorder will also continue to recurse into a given structure using a provided callback method.
The reason that the node type is provided to
apply
(instead ofReorder
) has to do with how generic trees are specified. Since TreeOps uses path-dependent types to specify node types, the current design is a bit of a kludge that makes it easy to get the types right when handling a Reorder instance to a TreeTraversal instance (which is parameterized on a generic tree type).