diff --git a/src/graph.rs b/src/graph.rs index 8d9f0ee..27f088f 100644 --- a/src/graph.rs +++ b/src/graph.rs @@ -2,7 +2,6 @@ use std::{ cell::RefCell, collections::{HashMap, HashSet}, rc::Rc, - result, }; #[derive(Debug)] @@ -11,6 +10,7 @@ pub struct AdjacencyGraph { adjacencies: HashMap>, } +#[allow(dead_code)] impl AdjacencyGraph { pub fn new() -> Self { AdjacencyGraph { @@ -137,14 +137,17 @@ impl AdjacencyGraph { while let Some(node) = stack.pop() { println!("New CC: {:?}", new_cc.borrow()); - new_cc.borrow_mut().insert(node.clone()); - if cc.contains_key(&node) { // merge the two connected components and go to the next node let old_cc = cc.get(&node).unwrap(); - println!("Merging {:?} with {:?}", new_cc.borrow(), old_cc.borrow()); + println!( + "Merging {:?} with {:?} due to link to {:?}", + new_cc.borrow(), + old_cc.borrow(), + node + ); new_cc .borrow_mut() @@ -157,6 +160,8 @@ impl AdjacencyGraph { continue; } + new_cc.borrow_mut().insert(node.clone()); + if let Some(adjacencies) = self.get_adjacencies(&node) { for adj in adjacencies { stack.push(adj.clone()); diff --git a/src/main.rs b/src/main.rs index 9d560a8..d640ecc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -76,7 +76,8 @@ fn main() -> std::io::Result<()> { ); } - let cc = graph.compute_ccs(); + let cc = graph.compute_ccs_2(); + println!("CCs: {:?}", cc); println!("Number of connected components: {}", cc.len()); } }