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
V: Ord + Clone,
{
fn nodes(&self) -> &BTreeSet<V> {
&self.nodes
fn nodes(&self) -> BTreeSet<V> {
self.nodes.clone()
}
fn adjacencies(&self) -> &BTreeMap<V, BTreeSet<V>> {
&self.adjacencies
fn adjacencies(&self) -> BTreeMap<V, BTreeSet<V>> {
self.adjacencies.clone()
}
fn edges(&self) -> BTreeMap<V, V> {
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<Item = (&V, &V)> {
// self.adjacencies
// .iter()
// .flat_map(|(from, tos)| tos.iter().map(move |to| (from, to)))
// }
}
impl<V> Graph<V> for UndirectedGraph<V>
where
V: Ord + Clone,
{
fn nodes(&self) -> &BTreeSet<V> {
fn nodes(&self) -> BTreeSet<V> {
self.directed.nodes()
}
fn adjacencies(&self) -> &BTreeMap<V, BTreeSet<V>> {
fn adjacencies(&self) -> BTreeMap<V, BTreeSet<V>> {
self.directed.adjacencies()
}
fn edges(&self) -> BTreeMap<V, V> {
fn edges(&self) -> BTreeSet<(V, V)> {
self.directed.edges()
}
}

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

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

Loading…
Cancel
Save