1 // Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 use super::super::indexed_vec::IndexVec;
12 use super::{DirectedGraph, WithSuccessors, WithNumNodes};
17 pub fn post_order_from<G: DirectedGraph + WithSuccessors + WithNumNodes>(
21 post_order_from_to(graph, start_node, None)
24 pub fn post_order_from_to<G: DirectedGraph + WithSuccessors + WithNumNodes>(
27 end_node: Option<G::Node>,
29 let mut visited: IndexVec<G::Node, bool> = IndexVec::from_elem_n(false, graph.num_nodes());
30 let mut result: Vec<G::Node> = Vec::with_capacity(graph.num_nodes());
31 if let Some(end_node) = end_node {
32 visited[end_node] = true;
34 post_order_walk(graph, start_node, &mut result, &mut visited);
38 fn post_order_walk<G: DirectedGraph + WithSuccessors + WithNumNodes>(
41 result: &mut Vec<G::Node>,
42 visited: &mut IndexVec<G::Node, bool>,
49 for successor in graph.successors(node) {
50 post_order_walk(graph, successor, result, visited);
56 pub fn reverse_post_order<G: DirectedGraph + WithSuccessors + WithNumNodes>(
60 let mut vec = post_order_from(graph, start_node);