Add Incidence struct for GraphTopology to use
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
//! [`AppendGraph`], an undirected graph topology supporting addition only.
|
||||
|
||||
use crate::maps::EntityMap;
|
||||
use crate::traits::{GraphTopology, IncidenceCursor};
|
||||
use crate::traits::{GraphTopology, Incidence, IncidenceCursor};
|
||||
|
||||
/// An opaque handle identifying a vertex in an [`AppendGraph`].
|
||||
///
|
||||
@@ -23,6 +23,9 @@ pub type AppendGraphVertexMap<T> = EntityMap<Vertex, T>;
|
||||
/// An [`EntityMap`] for [`AppendGraph`] edges.
|
||||
pub type AppendGraphEdgeMap<T> = EntityMap<Edge, T>;
|
||||
|
||||
/// An [`Incidence`] for [`AppendGraph`].
|
||||
pub type AppendGraphIncidence = Incidence<Vertex, Edge>;
|
||||
|
||||
impl Edge {
|
||||
fn normalize(&self) -> Self {
|
||||
Self(self.0 & !1)
|
||||
@@ -50,10 +53,13 @@ pub struct AppendGraphIncidenceCursor {
|
||||
}
|
||||
|
||||
impl IncidenceCursor<AppendGraph> for AppendGraphIncidenceCursor {
|
||||
fn next(&mut self, graph: &AppendGraph) -> Option<(Vertex, Edge)> {
|
||||
fn next(&mut self, graph: &AppendGraph) -> Option<AppendGraphIncidence> {
|
||||
graph
|
||||
.step_incidence(&mut self.incidence)
|
||||
.map(|(v, e)| (v, e.normalize()))
|
||||
.map(|(v, e)| Incidence {
|
||||
vertex: v,
|
||||
edge: e.normalize(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -191,8 +197,11 @@ impl GraphTopology for AppendGraph {
|
||||
self.raw_incidences(v).map(|(_, e)| e.normalize())
|
||||
}
|
||||
|
||||
fn incidences(&self, v: Self::Vertex) -> impl Iterator<Item = (Self::Vertex, Self::Edge)> {
|
||||
self.raw_incidences(v).map(|(v, e)| (v, e.normalize()))
|
||||
fn incidences(&self, v: Self::Vertex) -> impl Iterator<Item = AppendGraphIncidence> {
|
||||
self.raw_incidences(v).map(|(v, e)| Incidence {
|
||||
vertex: v,
|
||||
edge: e.normalize(),
|
||||
})
|
||||
}
|
||||
|
||||
fn incidence_cursor(&self, v: Self::Vertex) -> Self::IncidenceCursor {
|
||||
|
||||
+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