Renamed the private graph iterators to attune for upcoming changes

This commit is contained in:
2026-05-07 18:01:16 +02:00
parent a7be995e34
commit 4e47573290
2 changed files with 21 additions and 21 deletions
+3 -3
View File
@@ -23,12 +23,12 @@ struct IncidenceEntry {
adjacent: Vertex, adjacent: Vertex,
} }
struct VertexAdjacenceIterator<'a> { struct AdjacentVertexIterator<'a> {
graph: &'a AppendGraph, graph: &'a AppendGraph,
incidence: Option<Incidence>, incidence: Option<Incidence>,
} }
impl<'a> Iterator for VertexAdjacenceIterator<'a> { impl<'a> Iterator for AdjacentVertexIterator<'a> {
type Item = Vertex; type Item = Vertex;
fn next(&mut self) -> Option<Self::Item> { fn next(&mut self) -> Option<Self::Item> {
@@ -113,7 +113,7 @@ impl GraphTopology for AppendGraph {
} }
fn adjacent_vertices(&self, v: Self::Vertex) -> impl Iterator<Item = Self::Vertex> { fn adjacent_vertices(&self, v: Self::Vertex) -> impl Iterator<Item = Self::Vertex> {
VertexAdjacenceIterator { AdjacentVertexIterator {
graph: self, graph: self,
incidence: self.vertices[v.0].first_incidence, incidence: self.vertices[v.0].first_incidence,
} }
+18 -18
View File
@@ -23,50 +23,50 @@ pub struct IncidenceEntry {
adjacent: VertexSlot, adjacent: VertexSlot,
} }
struct VertexAdjacenceIterator<'a> { struct AdjacentVertexIterator<'a> {
graph: &'a Graph, graph: &'a Graph,
incidence: Option<IncidenceSlot>, incidence: Option<IncidenceSlot>,
} }
impl<'a> Iterator for VertexAdjacenceIterator<'a> { impl<'a> Iterator for AdjacentVertexIterator<'a> {
type Item = Vertex; type Item = Vertex;
fn next(&mut self) -> Option<Self::Item> { fn next(&mut self) -> Option<Self::Item> {
// TODO: Benchmark storing full Index (one read, larger entries) vs. slot + get_idx() (two reads, smaller entries). // TODO: Benchmark storing full Index (one read, larger entries) vs. slot + get_idx() (two reads, smaller entries).
let incidence = self.incidence?; let incidence = self.incidence?;
let index = self.graph.incidences.get_idx(incidence.0)?; let i = self.graph.incidences.get_idx(incidence.0).unwrap();
let entry = &self.graph.incidences[index]; let entry = &self.graph.incidences[i];
self.incidence = entry.next; self.incidence = entry.next;
self.graph.vertices.get_idx(entry.adjacent.0) Some(self.graph.vertices.get_idx(entry.adjacent.0).unwrap())
} }
} }
struct VertexIncidenceIterator<'a> { struct IncidentEdgeIterator<'a> {
graph: &'a Graph, graph: &'a Graph,
incidence: Option<IncidenceSlot>, incidence: Option<IncidenceSlot>,
} }
impl<'a> Iterator for VertexIncidenceIterator<'a> { impl<'a> Iterator for IncidentEdgeIterator<'a> {
type Item = Edge; type Item = Edge;
fn next(&mut self) -> Option<Self::Item> { fn next(&mut self) -> Option<Self::Item> {
let current = self.incidence?; let current = self.incidence?;
let index = self.graph.incidences.get_idx(current.0)?; let e = self.graph.incidences.get_idx(current.0).unwrap();
self.incidence = self.graph.incidences[index].next; self.incidence = self.graph.incidences[e].next;
Some(index) Some(e)
} }
} }
struct VertexIncidenceCursor { struct IncidentEdgeCursor {
incidence: Option<IncidenceSlot>, incidence: Option<IncidenceSlot>,
} }
impl VertexIncidenceCursor { impl IncidentEdgeCursor {
fn next(&mut self, graph: &Graph) -> Option<Edge> { fn next(&mut self, graph: &Graph) -> Option<Edge> {
let current = self.incidence?; let current = self.incidence?;
let index = graph.incidences.get_idx(current.0)?; let e = graph.incidences.get_idx(current.0).unwrap();
self.incidence = graph.incidences[index].next; self.incidence = graph.incidences[e].next;
Some(index) Some(e)
} }
} }
@@ -133,7 +133,7 @@ impl Graph {
if first.0 == e.arr_idx() { if first.0 == e.arr_idx() {
vertex_header.first_incidence = next; vertex_header.first_incidence = next;
} else { } else {
let previous = VertexIncidenceIterator { let previous = IncidentEdgeIterator {
graph: self, graph: self,
incidence: self.vertices[source_vertex].first_incidence, incidence: self.vertices[source_vertex].first_incidence,
} }
@@ -192,7 +192,7 @@ impl GraphTopology for Graph {
} }
fn adjacent_vertices(&self, v: Self::Vertex) -> impl Iterator<Item = Self::Vertex> { fn adjacent_vertices(&self, v: Self::Vertex) -> impl Iterator<Item = Self::Vertex> {
VertexAdjacenceIterator { AdjacentVertexIterator {
graph: self, graph: self,
incidence: self.vertices[v].first_incidence, incidence: self.vertices[v].first_incidence,
} }
@@ -226,7 +226,7 @@ impl GraphTopologyDeletion for Graph {
.vertices .vertices
.remove(v) .remove(v)
.expect("attempt to delete an invalid vertex"); .expect("attempt to delete an invalid vertex");
let mut cursor = VertexIncidenceCursor { let mut cursor = IncidentEdgeCursor {
incidence: v_header.first_incidence, incidence: v_header.first_incidence,
}; };
while let Some(e) = cursor.next(self) { while let Some(e) = cursor.next(self) {