Initial release #1

Merged
warrence merged 102 commits from dev into main 2026-06-30 10:26:52 +02:00
Showing only changes of commit 2eb054eb0c - Show all commits
+7 -21
View File
@@ -23,35 +23,19 @@ struct IncidenceEntry {
adjacent: Vertex, adjacent: Vertex,
} }
struct AdjacentVertexIterator<'a> { struct RawIncidenceIterator<'a> {
graph: &'a AppendGraph, graph: &'a AppendGraph,
incidence: Option<Incidence>, incidence: Option<Incidence>,
} }
impl<'a> Iterator for AdjacentVertexIterator<'a> { impl<'a> Iterator for RawIncidenceIterator<'a> {
type Item = Vertex;
fn next(&mut self) -> Option<Self::Item> {
let current = self.incidence?;
let entry = &self.graph.incidences[current.0];
self.incidence = entry.next;
Some(entry.adjacent)
}
}
struct IncidenceIterator<'a> {
graph: &'a AppendGraph,
incidence: Option<Incidence>,
}
impl<'a> Iterator for IncidenceIterator<'a> {
type Item = (Vertex, Incidence); type Item = (Vertex, Incidence);
fn next(&mut self) -> Option<Self::Item> { fn next(&mut self) -> Option<Self::Item> {
let current = self.incidence?; let current = self.incidence?;
let entry = &self.graph.incidences[current.0]; let entry = &self.graph.incidences[current.0];
self.incidence = entry.next; self.incidence = entry.next;
Some((entry.adjacent, current.normalize())) Some((entry.adjacent, current))
} }
} }
@@ -129,10 +113,11 @@ 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> {
AdjacentVertexIterator { RawIncidenceIterator {
graph: self, graph: self,
incidence: self.vertices[v.0].first_incidence, incidence: self.vertices[v.0].first_incidence,
} }
.map(|(v, _)| v)
} }
fn edges(&self) -> impl Iterator<Item = Self::Edge> { fn edges(&self) -> impl Iterator<Item = Self::Edge> {
@@ -140,10 +125,11 @@ impl GraphTopology for AppendGraph {
} }
fn incidences(&self, v: Self::Vertex) -> impl Iterator<Item = (Self::Vertex, Self::Edge)> { fn incidences(&self, v: Self::Vertex) -> impl Iterator<Item = (Self::Vertex, Self::Edge)> {
IncidenceIterator { RawIncidenceIterator {
graph: self, graph: self,
incidence: self.vertices[v.0].first_incidence, incidence: self.vertices[v.0].first_incidence,
} }
.map(|(v, e)| (v, e.normalize()))
} }
fn add_vertex(&mut self) -> Self::Vertex { fn add_vertex(&mut self) -> Self::Vertex {