From fed8d30de25f3c638d77f8c7e7a6445d41cbeee0 Mon Sep 17 00:00:00 2001 From: Antonio De Lucreziis Date: Tue, 29 Oct 2024 10:30:17 +0100 Subject: [PATCH] copilot allucination fix --- src/graph/algorithms.rs | 22 ++++++++++++++-------- src/graph/mod.rs | 6 +++--- src/main.rs | 9 +++++---- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/src/graph/algorithms.rs b/src/graph/algorithms.rs index 6c78ab4..cff1623 100644 --- a/src/graph/algorithms.rs +++ b/src/graph/algorithms.rs @@ -13,35 +13,41 @@ impl Graph for AdjacencyGraph where V: Ord + Clone, { - fn nodes(&self) -> &BTreeSet { - &self.nodes + fn nodes(&self) -> BTreeSet { + self.nodes.clone() } - fn adjacencies(&self) -> &BTreeMap> { - &self.adjacencies + fn adjacencies(&self) -> BTreeMap> { + self.adjacencies.clone() } - fn edges(&self) -> BTreeMap { + fn edges(&self) -> BTreeSet<(V, V)> { self.adjacencies .iter() .flat_map(|(from, tos)| tos.iter().map(move |to| (from.clone(), to.clone()))) .collect() } + + // pub fn edges(&self) -> impl Iterator { + // self.adjacencies + // .iter() + // .flat_map(|(from, tos)| tos.iter().map(move |to| (from, to))) + // } } impl Graph for UndirectedGraph where V: Ord + Clone, { - fn nodes(&self) -> &BTreeSet { + fn nodes(&self) -> BTreeSet { self.directed.nodes() } - fn adjacencies(&self) -> &BTreeMap> { + fn adjacencies(&self) -> BTreeMap> { self.directed.adjacencies() } - fn edges(&self) -> BTreeMap { + fn edges(&self) -> BTreeSet<(V, V)> { self.directed.edges() } } diff --git a/src/graph/mod.rs b/src/graph/mod.rs index e6f0a8b..c1892c3 100644 --- a/src/graph/mod.rs +++ b/src/graph/mod.rs @@ -7,9 +7,9 @@ pub trait Graph where V: Clone, { - fn nodes(&self) -> &BTreeSet; - fn adjacencies(&self) -> &BTreeMap>; - fn edges(&self) -> BTreeMap; + fn nodes(&self) -> BTreeSet; + fn adjacencies(&self) -> BTreeMap>; + fn edges(&self) -> BTreeSet<(V, V)>; } #[derive(Debug)] diff --git a/src/main.rs b/src/main.rs index 5c672ba..3b88a66 100644 --- a/src/main.rs +++ b/src/main.rs @@ -164,6 +164,7 @@ where }, ); + println!("Node count: {}", graph.nodes().len()); println!( "Edge count: {}, Total edge count: {}", graph.edges().count(), @@ -226,14 +227,14 @@ where let progress_bar = indicatif::ProgressBar::new(graph.edges().len() as u64); for (from, tos) in graph.adjacencies() { - *vertices_degrees.entry(from).or_insert(0) += tos.len(); - *vertices_out_degrees.entry(from).or_insert(0) += tos.len(); + *vertices_degrees.entry(from.clone()).or_insert(0) += tos.len(); + *vertices_out_degrees.entry(from.clone()).or_insert(0) += tos.len(); for to in tos { progress_bar.inc(1); - *vertices_degrees.entry(to).or_insert(0) += 1; - *vertices_in_degrees.entry(to).or_insert(0) += 1; + *vertices_degrees.entry(to.clone()).or_insert(0) += 1; + *vertices_in_degrees.entry(to.clone()).or_insert(0) += 1; } }