mirror of
https://github.com/aziis98/asd-2024.git
synced 2026-10-06 22:55:18 +00:00
testing other algorithm
This commit is contained in:
+9
-4
@@ -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());
|
||||
|
||||
+2
-1
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user