Fix IncidenceCursor for AppendGraph and Graph, and add tests

This commit is contained in:
2026-07-17 22:06:28 +02:00
parent 5fa415841e
commit 3fa4b66981
3 changed files with 212 additions and 20 deletions
+3 -1
View File
@@ -34,7 +34,9 @@ pub struct AppendGraphIncidenceCursor {
impl IncidenceCursor<AppendGraph> for AppendGraphIncidenceCursor {
fn next(&mut self, graph: &AppendGraph) -> Option<(Vertex, Edge)> {
graph.step_incidence(&mut self.incidence)
graph
.step_incidence(&mut self.incidence)
.map(|(v, e)| (v, e.normalize()))
}
}
+12 -4
View File
@@ -43,9 +43,12 @@ pub struct GraphIncidenceCursor {
impl IncidenceCursor<Graph> for GraphIncidenceCursor {
fn next(&mut self, graph: &Graph) -> Option<(Vertex, Edge)> {
graph
.step_incidence(&mut self.incidence)
.map(|(vs, e)| (graph.vertices.get_idx(vs.0).unwrap(), e))
graph.step_incidence(&mut self.incidence).map(|(vs, e)| {
(
graph.vertices.get_idx(vs.0).unwrap(),
graph.normalize_edge(e),
)
})
}
}
@@ -140,7 +143,12 @@ impl Graph {
}
fn normalize_edge(&self, e: Edge) -> Edge {
self.incidences.get_idx(e.arr_idx() & !1).unwrap()
let i = e.arr_idx();
if i & 1 == 0 {
e
} else {
self.incidences.get_idx(i ^ 1).unwrap()
}
}
}