Fix are_adjacent() method

Next incidence was not updated correctly, which could lead to bad results and infinite loops.
This commit is contained in:
2025-10-05 23:41:27 +02:00
parent b85edb1287
commit 58f330ef46
+4 -3
View File
@@ -33,16 +33,17 @@ impl Graph {
// TODO: 'fn are_adjacent()' could probably be done with a neighbor vertex iterator.
fn are_adjacent(&self, v1: Vertex, v2: Vertex) -> bool {
let Some(next) = self.vertex_incidence_headers[v1.0].first_incidence else {
let Some(mut incidence) = self.vertex_incidence_headers[v1.0].first_incidence else {
return false;
};
loop {
if self.incidence_vertices[next.0] == v2 {
if self.incidence_vertices[incidence.0] == v2 {
return true;
}
let Some(next) = self.next_incidences[next.0] else {
let Some(next) = self.next_incidences[incidence.0] else {
return false;
};
incidence = next;
}
}