diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2018-07-02 06:14:49 -0400 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2018-07-12 00:38:40 -0400 |
| commit | 90c90ba542635c3f2d1da71cb42569b6e7eeb6a9 (patch) | |
| tree | f3562242eda7cc1c634e6b8c05edae6c16072426 /src/librustc_data_structures/control_flow_graph/iterate | |
| parent | 3c30415e96b2152ce0c1e0474d3e7be0e597abc0 (diff) | |
rename `control_flow_graph` to `graph`
Diffstat (limited to 'src/librustc_data_structures/control_flow_graph/iterate')
| -rw-r--r-- | src/librustc_data_structures/control_flow_graph/iterate/mod.rs | 63 | ||||
| -rw-r--r-- | src/librustc_data_structures/control_flow_graph/iterate/test.rs | 21 |
2 files changed, 0 insertions, 84 deletions
diff --git a/src/librustc_data_structures/control_flow_graph/iterate/mod.rs b/src/librustc_data_structures/control_flow_graph/iterate/mod.rs deleted file mode 100644 index 3afdc88d602..00000000000 --- a/src/librustc_data_structures/control_flow_graph/iterate/mod.rs +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright 2016 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or -// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license -// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -use super::super::indexed_vec::IndexVec; -use super::{DirectedGraph, WithSuccessors, WithNumNodes}; - -#[cfg(test)] -mod test; - -pub fn post_order_from<G: DirectedGraph + WithSuccessors + WithNumNodes>( - graph: &G, - start_node: G::Node, -) -> Vec<G::Node> { - post_order_from_to(graph, start_node, None) -} - -pub fn post_order_from_to<G: DirectedGraph + WithSuccessors + WithNumNodes>( - graph: &G, - start_node: G::Node, - end_node: Option<G::Node>, -) -> Vec<G::Node> { - let mut visited: IndexVec<G::Node, bool> = IndexVec::from_elem_n(false, graph.num_nodes()); - let mut result: Vec<G::Node> = Vec::with_capacity(graph.num_nodes()); - if let Some(end_node) = end_node { - visited[end_node] = true; - } - post_order_walk(graph, start_node, &mut result, &mut visited); - result -} - -fn post_order_walk<G: DirectedGraph + WithSuccessors + WithNumNodes>( - graph: &G, - node: G::Node, - result: &mut Vec<G::Node>, - visited: &mut IndexVec<G::Node, bool>, -) { - if visited[node] { - return; - } - visited[node] = true; - - for successor in graph.successors(node) { - post_order_walk(graph, successor, result, visited); - } - - result.push(node); -} - -pub fn reverse_post_order<G: DirectedGraph + WithSuccessors + WithNumNodes>( - graph: &G, - start_node: G::Node, -) -> Vec<G::Node> { - let mut vec = post_order_from(graph, start_node); - vec.reverse(); - vec -} diff --git a/src/librustc_data_structures/control_flow_graph/iterate/test.rs b/src/librustc_data_structures/control_flow_graph/iterate/test.rs deleted file mode 100644 index 100881ddfdd..00000000000 --- a/src/librustc_data_structures/control_flow_graph/iterate/test.rs +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2016 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or -// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license -// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -use super::super::test::TestGraph; - -use super::*; - -#[test] -fn diamond_post_order() { - let graph = TestGraph::new(0, &[(0, 1), (0, 2), (1, 3), (2, 3)]); - - let result = post_order_from(&graph, 0); - assert_eq!(result, vec![3, 1, 2, 0]); -} |
