Initial release #1
+9
-6
@@ -98,8 +98,8 @@ impl Graph {
|
|||||||
vertex_header.first_incidence = next;
|
vertex_header.first_incidence = next;
|
||||||
} else {
|
} else {
|
||||||
let graph: &Graph = self;
|
let graph: &Graph = self;
|
||||||
let mut incidence = self.vertices[source_vertex].first_incidence;
|
let (_, previous) = self
|
||||||
let (_, previous) = std::iter::from_fn(move || graph.step_incidence(&mut incidence))
|
.raw_incidences(source_vertex)
|
||||||
.find(|(_, f)| {
|
.find(|(_, f)| {
|
||||||
graph.incidences[*f]
|
graph.incidences[*f]
|
||||||
.next
|
.next
|
||||||
@@ -110,6 +110,11 @@ impl Graph {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn raw_incidences(&self, v: Vertex) -> impl Iterator<Item = (VertexSlot, Edge)> {
|
||||||
|
let mut incidence = self.vertices[v].first_incidence;
|
||||||
|
std::iter::from_fn(move || self.step_incidence(&mut incidence))
|
||||||
|
}
|
||||||
|
|
||||||
fn step_incidence(&self, incidence: &mut Option<IncidenceSlot>) -> Option<(VertexSlot, Edge)> {
|
fn step_incidence(&self, incidence: &mut Option<IncidenceSlot>) -> Option<(VertexSlot, Edge)> {
|
||||||
let current = (*incidence)?;
|
let current = (*incidence)?;
|
||||||
let e = self.incidences.get_idx(current.0).unwrap();
|
let e = self.incidences.get_idx(current.0).unwrap();
|
||||||
@@ -171,8 +176,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> {
|
||||||
let mut incidence = self.vertices[v].first_incidence;
|
self.raw_incidences(v)
|
||||||
std::iter::from_fn(move || self.step_incidence(&mut incidence))
|
|
||||||
.map(|(vs, _)| self.vertices.get_idx(vs.0).unwrap())
|
.map(|(vs, _)| self.vertices.get_idx(vs.0).unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -197,8 +201,7 @@ impl GraphTopology for Graph {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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)> {
|
||||||
let mut incidence = self.vertices[v].first_incidence;
|
self.raw_incidences(v)
|
||||||
std::iter::from_fn(move || self.step_incidence(&mut incidence))
|
|
||||||
.map(|(vs, e)| (self.vertices.get_idx(vs.0).unwrap(), self.normalize_edge(e)))
|
.map(|(vs, e)| (self.vertices.get_idx(vs.0).unwrap(), self.normalize_edge(e)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user