From 58f330ef4635285c33ac3d683a2e36834f818cee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20M=C3=BCller?= Date: Sun, 5 Oct 2025 23:41:27 +0200 Subject: [PATCH] Fix are_adjacent() method Next incidence was not updated correctly, which could lead to bad results and infinite loops. --- src/main.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index bff4b7a..6768cac 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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; } }