mirror of
https://github.com/aziis98/asd-2024.git
synced 2026-10-06 22:55:18 +00:00
copilot allucination fix
This commit is contained in:
+14
-8
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -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)]
|
||||
|
||||
+5
-4
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user