Template Function sequant::canonical_children(TreeNode const&)¶
Defined in File eval_node_compare.hpp
Function Documentation¶
-
template<typename TreeNode>
std::pair<TreeNode const&, TreeNode const&> sequant::canonical_children(TreeNode const &n)¶ A node’s two children in canonical order — the order-independent view that every derivation of node identity reads them through.
Returns the children swapped iff
canonical_operand_cmpsays the right one belongs first. The node is left alone and nothing is cached on it: the decision is one comparison of two already-computed hashes, and leaving the tree untouched is the whole point — evaluation, slicing positions, operand reads, dry-run op costs and the peak sweep all keep the left/right the DP emitted.Meaningful for a commutative (Product) node; callers use the emitted order for everything else (a Sum’s left child is the in-place accumulator, an Adjoint’s right child is a sentinel), so this is not applied there.
Note
The returned pair holds references into
n, sonmust outlive it; binding a temporary is rejected by the deleted overload below.- Parameters:
n – a non-leaf node
- Pre:
nis not a leaf- Returns:
n'schildren, the canonically first one first