testing other algorithm

main
Antonio De Lucreziis 7 months ago
parent 607d2fc14b
commit e654535280

@ -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<String, HashSet<String>>,
}
#[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());

@ -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());
}
}

Loading…
Cancel
Save