diff --git a/thriller-core/src/dataflow/graph.rs b/thriller-core/src/dataflow/graph.rs index 7bf49e1..ea2327a 100644 --- a/thriller-core/src/dataflow/graph.rs +++ b/thriller-core/src/dataflow/graph.rs @@ -120,7 +120,33 @@ impl ThrillerGraph { } } +// Graph algorithms for [`ThrillerGraph`]. impl ThrillerGraph { + /// Depth-first search on the graph. + #[allow(dead_code)] + pub(crate) fn dfs(&self, _visted: &HashMap) { + todo!("dfs not implemented yet"); + } + + #[allow(dead_code)] + pub(crate) fn bfs( + &self, + start_node: &Rc>, + ) -> Vec>> { + let mut group = vec![]; + let mut queue = vec![start_node.clone()]; + + while let Some(node) = queue.pop() { + group.push(node.clone()); + let node_ref = node.borrow(); + node_ref.get_nexts().iter().for_each(|next_node| { + queue.push(next_node.clone()); + }); + } + + group + } + /// Try to find the disconnected subgraph in the graph. #[allow(dead_code)] pub(crate) fn try_find_disconnected_subgraph(&self) -> Option> {