Change GraphTopologyConversion::convert return value to include the new GraphIsomorphism

This allows to convert maps for the converted graph.
This commit is contained in:
2026-10-12 21:33:49 +02:00
parent 1979d33649
commit b124e58b38
9 changed files with 228 additions and 79 deletions
+12 -18
View File
@@ -3,7 +3,9 @@
use std::ops::IndexMut;
use crate::maps::ElementMap;
use crate::traits::{GraphTopology, GraphTopologyConversion, Incidence, IncidenceCursor};
use crate::traits::{
GraphIsomorphism, GraphTopology, GraphTopologyConversion, Incidence, IncidenceCursor,
};
/// An opaque handle identifying a vertex in a [`FrozenGraph`].
///
@@ -77,10 +79,10 @@ impl IncidenceCursor<FrozenGraph> for FrozenGraphIncidenceCursor {
/// let u = graph.add_vertex();
/// let v = graph.add_vertex();
/// let e = graph.add_edge(u, v);
/// let (graph, vertex_map, edge_map) = FrozenGraph::convert(&graph);
/// let (graph, isomorphism) = FrozenGraph::convert(&graph);
///
/// // Queries the FrozenGraph instance via the returned map.
/// assert!(graph.are_adjacent(vertex_map[u], vertex_map[v]));
/// assert!(graph.are_adjacent(isomorphism.vertex(u), isomorphism.vertex(v)));
/// ```
///
/// # Time and space complexity
@@ -193,13 +195,7 @@ impl GraphTopology for FrozenGraph {
}
impl GraphTopologyConversion for FrozenGraph {
fn convert<G: GraphTopology>(
source: &G,
) -> (
Self,
ElementMap<G::Vertex, Vertex>,
ElementMap<G::Edge, Edge>,
) {
fn convert<G: GraphTopology>(source: &G) -> (Self, GraphIsomorphism<G, Self>) {
// Builds vertex list with sentinel and vertex map.
let mut vertex_map = source.vertex_map(Vertex(usize::MAX));
let mut vertices = Vec::with_capacity(source.vertex_count() + 1);
@@ -237,14 +233,12 @@ impl GraphTopologyConversion for FrozenGraph {
}
}
(
Self {
vertices,
incidences,
},
vertex_map,
edge_map,
)
let result = Self {
vertices,
incidences,
};
let iso = GraphIsomorphism::new(&result, vertex_map, edge_map);
(result, iso)
}
}