Add GraphTopology::incident_vertices and tests
This commit is contained in:
@@ -120,6 +120,12 @@ impl GraphTopology for AppendGraph {
|
||||
.map(|(v, _)| v)
|
||||
}
|
||||
|
||||
fn incident_vertices(&self, e: Self::Edge) -> (Self::Vertex, Self::Vertex) {
|
||||
let v2 = self.incidences[e.0].adjacent;
|
||||
let v1 = self.incidences[e.0 ^ 1].adjacent;
|
||||
(v1, v2)
|
||||
}
|
||||
|
||||
fn edges(&self) -> impl Iterator<Item = Self::Edge> {
|
||||
(0..self.incidences.len()).step_by(2).map(Incidence)
|
||||
}
|
||||
@@ -153,4 +159,18 @@ mod tests {
|
||||
|
||||
crate::graph_topology_test_fixtures!(AppendGraph);
|
||||
crate::graph_topology_tests!(AppendGraph);
|
||||
|
||||
#[test]
|
||||
fn incident_vertices_paired_index() {
|
||||
let mut graph = AppendGraph::new();
|
||||
let v1 = graph.add_vertex();
|
||||
let v2 = graph.add_vertex();
|
||||
let e = graph.add_edge(v1, v2);
|
||||
let f = Incidence(e.0 + 1);
|
||||
let (u1, u2) = graph.incident_vertices(f);
|
||||
assert!(
|
||||
(u1 == v1 && u2 == v2) || (u1 == v2 && u2 == v1),
|
||||
"unexpected incident vertices {u1:?} and {u2:?} for edge {f:?}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user