Add Incidence struct for GraphTopology to use
This commit is contained in:
+16
-11
@@ -3,7 +3,7 @@
|
||||
use typed_generational_arena::{Arena, Index};
|
||||
|
||||
use crate::maps::EntityMap;
|
||||
use crate::traits::{GraphTopology, GraphTopologyDeletion, IncidenceCursor};
|
||||
use crate::traits::{GraphTopology, GraphTopologyDeletion, Incidence, IncidenceCursor};
|
||||
|
||||
/// An opaque handle identifying a vertex in a [`Graph`].
|
||||
///
|
||||
@@ -23,6 +23,9 @@ pub type GraphVertexMap<T> = EntityMap<Vertex, T>;
|
||||
/// An [`EntityMap`] for [`Graph`] edges.
|
||||
pub type GraphEdgeMap<T> = EntityMap<Edge, T>;
|
||||
|
||||
/// An [`Incidence`] for [`Graph`].
|
||||
pub type GraphIncidence = Incidence<Vertex, Edge>;
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
|
||||
struct VertexSlot(usize);
|
||||
|
||||
@@ -66,13 +69,13 @@ 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(),
|
||||
graph.normalize_edge(e),
|
||||
)
|
||||
})
|
||||
fn next(&mut self, graph: &Graph) -> Option<GraphIncidence> {
|
||||
graph
|
||||
.step_incidence(&mut self.incidence)
|
||||
.map(|(vs, e)| Incidence {
|
||||
vertex: graph.vertices.get_idx(vs.0).unwrap(),
|
||||
edge: graph.normalize_edge(e),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -297,9 +300,11 @@ impl GraphTopology for Graph {
|
||||
self.raw_incidences(v).map(|(_, e)| self.normalize_edge(e))
|
||||
}
|
||||
|
||||
fn incidences(&self, v: Self::Vertex) -> impl Iterator<Item = (Self::Vertex, Self::Edge)> {
|
||||
self.raw_incidences(v)
|
||||
.map(|(vs, e)| (self.vertices.get_idx(vs.0).unwrap(), self.normalize_edge(e)))
|
||||
fn incidences(&self, v: Self::Vertex) -> impl Iterator<Item = GraphIncidence> {
|
||||
self.raw_incidences(v).map(|(vs, e)| Incidence {
|
||||
vertex: self.vertices.get_idx(vs.0).unwrap(),
|
||||
edge: self.normalize_edge(e),
|
||||
})
|
||||
}
|
||||
|
||||
fn incidence_cursor(&self, v: Self::Vertex) -> Self::IncidenceCursor {
|
||||
|
||||
Reference in New Issue
Block a user