Change GraphTopologyConversion::convert return value to include the new GraphIsomorphism
This allows to convert maps for the converted graph.
This commit is contained in:
@@ -5,7 +5,8 @@ use std::num::NonZeroUsize;
|
||||
use crate::maps::ElementMap;
|
||||
use crate::models;
|
||||
use crate::traits::{
|
||||
GraphTopology, GraphTopologyAddition, GraphTopologyConversion, Incidence, IncidenceCursor,
|
||||
GraphIsomorphism, GraphTopology, GraphTopologyAddition, GraphTopologyConversion, Incidence,
|
||||
IncidenceCursor,
|
||||
};
|
||||
|
||||
/// An opaque handle identifying a vertex in an [`AppendGraph`].
|
||||
@@ -261,17 +262,12 @@ impl GraphTopologyAddition for AppendGraph {
|
||||
}
|
||||
|
||||
impl GraphTopologyConversion for AppendGraph {
|
||||
fn convert<H: GraphTopology>(
|
||||
source: &H,
|
||||
) -> (
|
||||
Self,
|
||||
ElementMap<H::Vertex, Vertex>,
|
||||
ElementMap<H::Edge, Edge>,
|
||||
) {
|
||||
fn convert<G: GraphTopology>(source: &G) -> (Self, GraphIsomorphism<G, Self>) {
|
||||
let mut edge_map = source.edge_map(Edge(NonZeroUsize::MAX));
|
||||
let (result, vertex_map) =
|
||||
models::convert_to_addition(source, Vertex(usize::MAX), |e, new_e| edge_map[e] = new_e);
|
||||
(result, vertex_map, edge_map)
|
||||
let iso = GraphIsomorphism::new(&result, vertex_map, edge_map);
|
||||
(result, iso)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+12
-18
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+5
-10
@@ -6,8 +6,8 @@ use typed_generational_arena::{Arena, Index};
|
||||
use crate::maps::ElementMap;
|
||||
use crate::models;
|
||||
use crate::traits::{
|
||||
GraphTopology, GraphTopologyAddition, GraphTopologyConversion, GraphTopologyDeletion,
|
||||
Incidence, IncidenceCursor,
|
||||
GraphIsomorphism, GraphTopology, GraphTopologyAddition, GraphTopologyConversion,
|
||||
GraphTopologyDeletion, Incidence, IncidenceCursor,
|
||||
};
|
||||
|
||||
/// An opaque handle identifying a vertex in a [`Graph`].
|
||||
@@ -399,19 +399,14 @@ impl GraphTopologyDeletion for Graph {
|
||||
}
|
||||
|
||||
impl GraphTopologyConversion for Graph {
|
||||
fn convert<H: GraphTopology>(
|
||||
source: &H,
|
||||
) -> (
|
||||
Self,
|
||||
ElementMap<H::Vertex, Vertex>,
|
||||
ElementMap<H::Edge, Edge>,
|
||||
) {
|
||||
fn convert<G: GraphTopology>(source: &G) -> (Self, GraphIsomorphism<G, Self>) {
|
||||
let mut edge_map = source.edge_map(Edge::new(usize::MAX, usize::MAX));
|
||||
let (result, vertex_map) =
|
||||
models::convert_to_addition(source, Vertex::new(usize::MAX, usize::MAX), |e, new_e| {
|
||||
edge_map[e] = new_e
|
||||
});
|
||||
(result, vertex_map, edge_map)
|
||||
let iso = GraphIsomorphism::new(&result, vertex_map, edge_map);
|
||||
(result, iso)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user