copilot allucination fix

main
Antonio De Lucreziis 3 weeks ago
parent b0d9573419
commit fed8d30de2

@ -13,35 +13,41 @@ impl<V> Graph<V> for AdjacencyGraph<V>
where where
V: Ord + Clone, V: Ord + Clone,
{ {
fn nodes(&self) -> &BTreeSet<V> { fn nodes(&self) -> BTreeSet<V> {
&self.nodes self.nodes.clone()
} }
fn adjacencies(&self) -> &BTreeMap<V, BTreeSet<V>> { fn adjacencies(&self) -> BTreeMap<V, BTreeSet<V>> {
&self.adjacencies self.adjacencies.clone()
} }
fn edges(&self) -> BTreeMap<V, V> { fn edges(&self) -> BTreeSet<(V, V)> {
self.adjacencies self.adjacencies
.iter() .iter()
.flat_map(|(from, tos)| tos.iter().map(move |to| (from.clone(), to.clone()))) .flat_map(|(from, tos)| tos.iter().map(move |to| (from.clone(), to.clone())))
.collect() .collect()
} }
// pub fn edges(&self) -> impl Iterator<Item = (&V, &V)> {
// self.adjacencies
// .iter()
// .flat_map(|(from, tos)| tos.iter().map(move |to| (from, to)))
// }
} }
impl<V> Graph<V> for UndirectedGraph<V> impl<V> Graph<V> for UndirectedGraph<V>
where where
V: Ord + Clone, V: Ord + Clone,
{ {
fn nodes(&self) -> &BTreeSet<V> { fn nodes(&self) -> BTreeSet<V> {
self.directed.nodes() self.directed.nodes()
} }
fn adjacencies(&self) -> &BTreeMap<V, BTreeSet<V>> { fn adjacencies(&self) -> BTreeMap<V, BTreeSet<V>> {
self.directed.adjacencies() self.directed.adjacencies()
} }
fn edges(&self) -> BTreeMap<V, V> { fn edges(&self) -> BTreeSet<(V, V)> {
self.directed.edges() self.directed.edges()
} }
} }

@ -7,9 +7,9 @@ pub trait Graph<V>
where where
V: Clone, V: Clone,
{ {
fn nodes(&self) -> &BTreeSet<V>; fn nodes(&self) -> BTreeSet<V>;
fn adjacencies(&self) -> &BTreeMap<V, BTreeSet<V>>; fn adjacencies(&self) -> BTreeMap<V, BTreeSet<V>>;
fn edges(&self) -> BTreeMap<V, V>; fn edges(&self) -> BTreeSet<(V, V)>;
} }
#[derive(Debug)] #[derive(Debug)]

@ -164,6 +164,7 @@ where
}, },
); );
println!("Node count: {}", graph.nodes().len());
println!( println!(
"Edge count: {}, Total edge count: {}", "Edge count: {}, Total edge count: {}",
graph.edges().count(), graph.edges().count(),
@ -226,14 +227,14 @@ where
let progress_bar = indicatif::ProgressBar::new(graph.edges().len() as u64); let progress_bar = indicatif::ProgressBar::new(graph.edges().len() as u64);
for (from, tos) in graph.adjacencies() { for (from, tos) in graph.adjacencies() {
*vertices_degrees.entry(from).or_insert(0) += tos.len(); *vertices_degrees.entry(from.clone()).or_insert(0) += tos.len();
*vertices_out_degrees.entry(from).or_insert(0) += tos.len(); *vertices_out_degrees.entry(from.clone()).or_insert(0) += tos.len();
for to in tos { for to in tos {
progress_bar.inc(1); progress_bar.inc(1);
*vertices_degrees.entry(to).or_insert(0) += 1; *vertices_degrees.entry(to.clone()).or_insert(0) += 1;
*vertices_in_degrees.entry(to).or_insert(0) += 1; *vertices_in_degrees.entry(to.clone()).or_insert(0) += 1;
} }
} }

Loading…
Cancel
Save