Skip to content

Commit

Permalink
Add BFS for ThrillerGraph.
Browse files Browse the repository at this point in the history
  • Loading branch information
KuangjuX committed May 30, 2024
1 parent 97aa027 commit 79a6896
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions thriller-core/src/dataflow/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<usize, bool>) {
todo!("dfs not implemented yet");
}

#[allow(dead_code)]
pub(crate) fn bfs(
&self,
start_node: &Rc<RefCell<ThrillerNode>>,
) -> Vec<Rc<RefCell<ThrillerNode>>> {
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<Vec<ThrillerGraph>> {
Expand Down

0 comments on commit 79a6896

Please sign in to comment.