pub fn forest_topo_sort(&self) -> Option<Vec<usize>> {
        let mut topo_sort = Vec::with_capacity(self.n_nodes());
        let mut visited = Vec::with_capacity(self.n_nodes());
        for _ in 0..self.node_potentials.len() {
            visited.push(false);
        }
        for candidate_root in 0..self.n_nodes() {
            if !visited[candidate_root] {
                // add a new tree, rooted here
                match self.tree_topo_sort(candidate_root) {
                    Some(mut sort_order) => {
                        for &node in sort_order.iter() {
                            visited[node] = true;
                        }
                        topo_sort.append(&mut sort_order);
                    }
                    None => {
                        return None;
                    }
                }
            }
        }
        Some(topo_sort)
    }
/// Topologically sort the full graph, assuming it is a forest
/// roots are always the nodes with lowest index in a tree
/// If the graph is not a forest, returns None
Topologically sort the full graph, assuming it is a forest
roots are always the nodes with lowest index in a tree
If the graph is not a forest, returns None
Topologically sort the full graph assuming it is a forest roots are always the nodes with lowest index in a tree If the graph is not a forest returns None
pub fn forest_topo_sort(&self) -> Option<Vec<usize>> {
        let mut topo_sort = Vec::with_capacity(self.n_nodes());
        let mut visited = Vec::with_capacity(self.n_nodes());
        for _ in 0..self.node_potentials.len() {
            visited.push(false);
        }
        for candidate_root in 0..self.n_nodes() {
            if !visited[candidate_root] {
                // add a new tree, rooted here
                match self.tree_topo_sort(candidate_root) {
                    Some(mut sort_order) => {
                        for &node in sort_order.iter() {
                            visited[node] = true;
                        }
                        topo_sort.append(&mut sort_order);
                    }
                    None => {
                        return None;
                    }
                }
            }
        }
        Some(topo_sort)
    }
pub fn forest_topo_sort ( & self ) -> Option < Vec < usize > > { let mut topo_sort = Vec :: with_capacity ( self . n_nodes ( ) ) ; let mut visited = Vec :: with_capacity ( self . n_nodes ( ) ) ; for _ in 0 .. self . node_potentials . len ( ) { visited . push ( false ) ; } for candidate_root in 0 .. self . n_nodes ( ) { if ! visited [ candidate_root ] { // add a new tree, rooted here match self . tree_topo_sort ( candidate_root ) { Some ( mut sort_order ) => { for & node in sort_order . iter ( ) { visited [ node ] = true ; } topo_sort . append ( & mut sort_order ) ; } None => { return None ; } } } } Some ( topo_sort ) }
Topologically sort the full graph, assuming it is a forest
roots are always the nodes with lowest index in a tree
If the graph is not a forest, returns None
Topologically sort the full graph assuming it is a forest roots are always the nodes with lowest index in a tree If the graph is not a forest returns None
&self