/// Deterministically extract the strongly connected components of a directed graph, reverse topologically sorted.
///
/// The order of nodes within the [Scc::Cyclic] variant is determined by the `compare` function.
Deterministically extract the strongly connected components of a directed graph, reverse topologically sorted.
The order of nodes within the [Scc::Cyclic] variant is determined by the `compare` function.
Deterministically extract the strongly connected components of a directed graph reverse topologically sorted . The order of nodes within the [ Scc :: Cyclic ] variant is determined by the ` compare ` function .
pub fn toposort_deterministic<Node, Key, GetKey, GetConnectedNodes, Compare>(
    nodes: Vec<Node>,
    get_key: GetKey,
    get_connected_nodes: GetConnectedNodes,
    compare: Compare,
) -> Vec<Scc<Node>>
where
    Node: Clone,
    Key: Clone + Eq + Hash + std::fmt::Debug,
    GetKey: Fn(&Node) -> Key,
    GetConnectedNodes: Fn(&Node) -> HashSet<Key>,
    Compare: Fn(&Node, &Node) -> std::cmp::Ordering + Copy,
{
    let mut sccs = toposort(nodes, get_key, get_connected_nodes);
    sccs.iter_mut().for_each(|scc| match scc {
        Scc::Acyclic(_) => {}
        Scc::Cyclic(nodes) if nodes.len() > 1 => {
            nodes.sort_by(compare);
        }
        Scc::Cyclic(_) => {}
    });
    sccs
}
pub fn toposort_deterministic < Node , Key , GetKey , GetConnectedNodes , Compare > ( nodes : Vec < Node > , get_key : GetKey , get_connected_nodes : GetConnectedNodes , compare : Compare , ) -> Vec < Scc < Node > > where Node : Clone , Key : Clone + Eq + Hash + std :: fmt :: Debug , GetKey : Fn ( & Node ) -> Key , GetConnectedNodes : Fn ( & Node ) -> HashSet < Key > , Compare : Fn ( & Node , & Node ) -> std :: cmp :: Ordering + Copy , { let mut sccs = toposort ( nodes , get_key , get_connected_nodes ) ; sccs . iter_mut ( ) . for_each ( | scc | match scc { Scc :: Acyclic ( _ ) => { } Scc :: Cyclic ( nodes ) if nodes . len ( ) > 1 => { nodes . sort_by ( compare ) ; } Scc :: Cyclic ( _ ) => { } } ) ; sccs }
Deterministically extract the strongly connected components of a directed graph, reverse topologically sorted.
Deterministically extract the strongly connected components of a directed graph reverse topologically sorted .
nodes
Vec<Node>
get_key
GetKey
get_connected_nodes
GetConnectedNodes
compare
Compare