retworkx_core/traversal/
mod.rs

1// Licensed under the Apache License, Version 2.0 (the "License"); you may
2// not use this file except in compliance with the License. You may obtain
3// a copy of the License at
4//
5//     http://www.apache.org/licenses/LICENSE-2.0
6//
7// Unless required by applicable law or agreed to in writing, software
8// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10// License for the specific language governing permissions and limitations
11// under the License.
12
13//! Module for graph traversal algorithms.
14
15mod bfs_visit;
16mod dfs_edges;
17mod dfs_visit;
18mod dijkstra_visit;
19
20pub use bfs_visit::{breadth_first_search, BfsEvent};
21pub use dfs_edges::dfs_edges;
22pub use dfs_visit::{depth_first_search, DfsEvent};
23pub use dijkstra_visit::{dijkstra_search, DijkstraEvent};
24
25/// Return if the expression is a break value, execute the provided statement
26/// if it is a prune value.
27/// https://github.com/petgraph/petgraph/blob/0.6.0/src/visit/dfsvisit.rs#L27
28macro_rules! try_control {
29    ($e:expr, $p:stmt) => {
30        try_control!($e, $p, ());
31    };
32    ($e:expr, $p:stmt, $q:stmt) => {
33        match $e {
34            x => {
35                if x.should_break() {
36                    return x;
37                } else if x.should_prune() {
38                    $p
39                } else {
40                    $q
41                }
42            }
43        }
44    };
45}
46
47use try_control;