Rename find_path* algorithms to dfs_find_path*
This commit is contained in:
+3
-3
@@ -261,14 +261,14 @@ where
|
|||||||
(visited, None)
|
(visited, None)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn find_path<G>(graph: &G, source: G::Vertex, target: G::Vertex) -> Option<Vec<G::Edge>>
|
pub fn dfs_find_path<G>(graph: &G, source: G::Vertex, target: G::Vertex) -> Option<Vec<G::Edge>>
|
||||||
where
|
where
|
||||||
G: GraphTopology,
|
G: GraphTopology,
|
||||||
{
|
{
|
||||||
find_path_where(graph, source, |v| v == target)
|
dfs_find_path_where(graph, source, |v| v == target)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn find_path_where<G, P>(graph: &G, source: G::Vertex, predicate: P) -> Option<Vec<G::Edge>>
|
pub fn dfs_find_path_where<G, P>(graph: &G, source: G::Vertex, predicate: P) -> Option<Vec<G::Edge>>
|
||||||
where
|
where
|
||||||
G: GraphTopology,
|
G: GraphTopology,
|
||||||
P: Fn(G::Vertex) -> bool,
|
P: Fn(G::Vertex) -> bool,
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ macro_rules! find_path_tests {
|
|||||||
let mut graph = <$T>::new();
|
let mut graph = <$T>::new();
|
||||||
let v = graph.add_vertex();
|
let v = graph.add_vertex();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
$crate::algorithms::find_path(&graph, v, v),
|
$crate::algorithms::dfs_find_path(&graph, v, v),
|
||||||
Some(vec![]),
|
Some(vec![]),
|
||||||
"path from source to itself should be empty"
|
"path from source to itself should be empty"
|
||||||
);
|
);
|
||||||
@@ -17,7 +17,7 @@ macro_rules! find_path_tests {
|
|||||||
fn find_path_disconnected() {
|
fn find_path_disconnected() {
|
||||||
let (graph, vertices) = make_test_graph_disconnected();
|
let (graph, vertices) = make_test_graph_disconnected();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
$crate::algorithms::find_path(&graph, vertices[0], vertices[1]),
|
$crate::algorithms::dfs_find_path(&graph, vertices[0], vertices[1]),
|
||||||
None,
|
None,
|
||||||
"no path should exist to disconnected vertex"
|
"no path should exist to disconnected vertex"
|
||||||
);
|
);
|
||||||
@@ -30,7 +30,7 @@ macro_rules! find_path_tests {
|
|||||||
let v1 = graph.add_vertex();
|
let v1 = graph.add_vertex();
|
||||||
let v2 = graph.add_vertex();
|
let v2 = graph.add_vertex();
|
||||||
let e = graph.add_edge(v1, v2);
|
let e = graph.add_edge(v1, v2);
|
||||||
let path = $crate::algorithms::find_path(&graph, v1, v2)
|
let path = $crate::algorithms::dfs_find_path(&graph, v1, v2)
|
||||||
.expect("path should exist between adjacent vertices");
|
.expect("path should exist between adjacent vertices");
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
path.len(),
|
path.len(),
|
||||||
@@ -43,7 +43,7 @@ macro_rules! find_path_tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn find_path() {
|
fn find_path() {
|
||||||
let (graph, vertices, _, _) = make_test_graph();
|
let (graph, vertices, _, _) = make_test_graph();
|
||||||
let path = $crate::algorithms::find_path(&graph, vertices[0], vertices[9])
|
let path = $crate::algorithms::dfs_find_path(&graph, vertices[0], vertices[9])
|
||||||
.expect(&format!(
|
.expect(&format!(
|
||||||
"path should exist between connected vertices {:?} and {:?}",
|
"path should exist between connected vertices {:?} and {:?}",
|
||||||
vertices[0], vertices[9]
|
vertices[0], vertices[9]
|
||||||
@@ -57,7 +57,7 @@ macro_rules! find_path_tests {
|
|||||||
let mut graph = <$T>::new();
|
let mut graph = <$T>::new();
|
||||||
let v = graph.add_vertex();
|
let v = graph.add_vertex();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
$crate::algorithms::find_path_where(&graph, v, |u| u == v),
|
$crate::algorithms::dfs_find_path_where(&graph, v, |u| u == v),
|
||||||
Some(vec![]),
|
Some(vec![]),
|
||||||
"path from source to itself should be empty"
|
"path from source to itself should be empty"
|
||||||
);
|
);
|
||||||
@@ -67,7 +67,7 @@ macro_rules! find_path_tests {
|
|||||||
fn find_path_where_disconnected() {
|
fn find_path_where_disconnected() {
|
||||||
let (graph, vertices) = make_test_graph_disconnected();
|
let (graph, vertices) = make_test_graph_disconnected();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
$crate::algorithms::find_path_where(&graph, vertices[0], |v| v == vertices[1]),
|
$crate::algorithms::dfs_find_path_where(&graph, vertices[0], |v| v == vertices[1]),
|
||||||
None,
|
None,
|
||||||
"no path should exist to disconnected vertex"
|
"no path should exist to disconnected vertex"
|
||||||
);
|
);
|
||||||
@@ -77,7 +77,7 @@ macro_rules! find_path_tests {
|
|||||||
fn find_path_where_no_match() {
|
fn find_path_where_no_match() {
|
||||||
let (graph, vertices, _, _) = make_test_graph();
|
let (graph, vertices, _, _) = make_test_graph();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
$crate::algorithms::find_path_where(&graph, vertices[0], |_| false),
|
$crate::algorithms::dfs_find_path_where(&graph, vertices[0], |_| false),
|
||||||
None,
|
None,
|
||||||
"no path should exist when predicate never matches"
|
"no path should exist when predicate never matches"
|
||||||
);
|
);
|
||||||
@@ -87,7 +87,7 @@ macro_rules! find_path_tests {
|
|||||||
fn find_path_where() {
|
fn find_path_where() {
|
||||||
let (graph, vertices, _, _) = make_test_graph();
|
let (graph, vertices, _, _) = make_test_graph();
|
||||||
let path =
|
let path =
|
||||||
$crate::algorithms::find_path_where(&graph, vertices[0], |v| v == vertices[9])
|
$crate::algorithms::dfs_find_path_where(&graph, vertices[0], |v| v == vertices[9])
|
||||||
.expect(&format!(
|
.expect(&format!(
|
||||||
"path should exist between connected vertices {:?} and {:?}",
|
"path should exist between connected vertices {:?} and {:?}",
|
||||||
vertices[0], vertices[9]
|
vertices[0], vertices[9]
|
||||||
|
|||||||
Reference in New Issue
Block a user