# [−][src]Function tree_mem_sort::sort_dag

pub fn sort_dag<T, P, C>(nodes: &mut [T], parents: P, children: C) where

P: Fn(&mut T) -> &mut [usize],

C: Fn(&mut T) -> &mut [usize],

The same algorithm as `sort`

, but for Directed Acyclic Graphs (DAGs),
encoded as trees with shared nodes.

WARNING: To avoid an infinite loop, one must be careful about the order of children.
E.g. if `A`

has children `C, B`

and `B`

has child `C`

, then the tree is not a DAG.
This is because the order of children is preserved after sorting.