diff options
| author | Maybe Waffle <waffle.lapkin@gmail.com> | 2024-04-14 16:03:08 +0000 |
|---|---|---|
| committer | Maybe Waffle <waffle.lapkin@gmail.com> | 2024-04-14 16:03:08 +0000 |
| commit | e8d2221e3bbb4e8971c97395463036ebd6e7b23d (patch) | |
| tree | c20a424652e88a7b6f26355bc998a40ab983baad /compiler/rustc_data_structures/src | |
| parent | 3124fa93107d406dc77e56a0b8a5b372349a73ab (diff) | |
| download | rust-e8d2221e3bbb4e8971c97395463036ebd6e7b23d.tar.gz rust-e8d2221e3bbb4e8971c97395463036ebd6e7b23d.zip | |
Make `depth_first_search` into a standalone function
Does not necessarily change much, but we never overwrite it, so I see no reason for it to be in the `Successors` trait. (+we already have a similar `is_cyclic`)
Diffstat (limited to 'compiler/rustc_data_structures/src')
| -rw-r--r-- | compiler/rustc_data_structures/src/graph/mod.rs | 11 | ||||
| -rw-r--r-- | compiler/rustc_data_structures/src/graph/vec_graph/tests.rs | 4 |
2 files changed, 10 insertions, 5 deletions
diff --git a/compiler/rustc_data_structures/src/graph/mod.rs b/compiler/rustc_data_structures/src/graph/mod.rs index 189474395ee..61bee2ee0bb 100644 --- a/compiler/rustc_data_structures/src/graph/mod.rs +++ b/compiler/rustc_data_structures/src/graph/mod.rs @@ -30,10 +30,6 @@ pub trait Successors: DirectedGraph { Self: 'g; fn successors(&self, node: Self::Node) -> Self::Successors<'_>; - - fn depth_first_search(&self, from: Self::Node) -> iterate::DepthFirstSearch<'_, Self> { - iterate::DepthFirstSearch::new(self).with_start_node(from) - } } pub trait Predecessors: DirectedGraph { @@ -57,3 +53,10 @@ where .run_from_start(&mut iterate::CycleDetector) .is_some() } + +pub fn depth_first_search<G>(graph: &G, from: G::Node) -> iterate::DepthFirstSearch<'_, G> +where + G: ?Sized + Successors, +{ + iterate::DepthFirstSearch::new(graph).with_start_node(from) +} diff --git a/compiler/rustc_data_structures/src/graph/vec_graph/tests.rs b/compiler/rustc_data_structures/src/graph/vec_graph/tests.rs index 7c866da6009..87c8d25f094 100644 --- a/compiler/rustc_data_structures/src/graph/vec_graph/tests.rs +++ b/compiler/rustc_data_structures/src/graph/vec_graph/tests.rs @@ -1,3 +1,5 @@ +use crate::graph; + use super::*; fn create_graph() -> VecGraph<usize> { @@ -37,6 +39,6 @@ fn successors() { #[test] fn dfs() { let graph = create_graph(); - let dfs: Vec<_> = graph.depth_first_search(0).collect(); + let dfs: Vec<_> = graph::depth_first_search(&graph, 0).collect(); assert_eq!(dfs, vec![0, 1, 3, 4, 2]); } |
