Move FromGrath trait within traits module
This commit is contained in:
+34
-33
@@ -237,39 +237,6 @@ pub trait GraphTopologyDeletion: GraphTopology {
|
|||||||
fn delete_edge(&mut self, e: Self::Edge);
|
fn delete_edge(&mut self, e: Self::Edge);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A trait for constructing an undirected graph topology by converting another graph
|
|
||||||
/// implementation to this one.
|
|
||||||
pub trait FromGraph: GraphTopology {
|
|
||||||
/// Creates a new graph instance that is isomorphic to `source`.
|
|
||||||
///
|
|
||||||
/// Returns the copied graph instance and two mappings from the vertices and edges of `source`
|
|
||||||
/// to the corresponding vertices and edges of the returned graph.
|
|
||||||
///
|
|
||||||
/// # Examples
|
|
||||||
///
|
|
||||||
/// ```
|
|
||||||
/// use grapherity::prelude::*;
|
|
||||||
/// use grapherity::models::{AppendGraph, FrozenGraph};
|
|
||||||
///
|
|
||||||
/// let mut source = AppendGraph::new();
|
|
||||||
/// let u = source.add_vertex();
|
|
||||||
/// let v = source.add_vertex();
|
|
||||||
/// let e = source.add_edge(u, v);
|
|
||||||
/// let (graph, vertex_map, edge_map) = FrozenGraph::from_graph(&source);
|
|
||||||
///
|
|
||||||
/// assert!(graph.are_adjacent(vertex_map[u], vertex_map[v]));
|
|
||||||
/// ```
|
|
||||||
fn from_graph<G: GraphTopology>(
|
|
||||||
source: &G,
|
|
||||||
) -> (
|
|
||||||
Self,
|
|
||||||
ElementMap<G::Vertex, Self::Vertex>,
|
|
||||||
ElementMap<G::Edge, Self::Edge>,
|
|
||||||
)
|
|
||||||
where
|
|
||||||
Self: Sized;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A cursor for traversing the incidences of a vertex one step at a time.
|
/// A cursor for traversing the incidences of a vertex one step at a time.
|
||||||
///
|
///
|
||||||
/// Because the cursor is [`Copy`], its state can be saved and restored to replay or branch a
|
/// Because the cursor is [`Copy`], its state can be saved and restored to replay or branch a
|
||||||
@@ -320,3 +287,37 @@ pub struct Incidence<V, E> {
|
|||||||
/// The edge between *v* and [`vertex`](Self::vertex).
|
/// The edge between *v* and [`vertex`](Self::vertex).
|
||||||
pub edge: E,
|
pub edge: E,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO-0.3.0: Provide and document a way to transform an ElementMap for source to an ElementMap for the copy.
|
||||||
|
/// A trait for constructing an undirected graph topology by converting another graph
|
||||||
|
/// implementation to this one.
|
||||||
|
pub trait FromGraph: GraphTopology {
|
||||||
|
/// Creates a new graph instance that is isomorphic to `source`.
|
||||||
|
///
|
||||||
|
/// Returns the copied graph instance and two mappings from the vertices and edges of `source`
|
||||||
|
/// to the corresponding vertices and edges of the returned graph.
|
||||||
|
///
|
||||||
|
/// # Examples
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// use grapherity::prelude::*;
|
||||||
|
/// use grapherity::models::{AppendGraph, FrozenGraph};
|
||||||
|
///
|
||||||
|
/// let mut source = AppendGraph::new();
|
||||||
|
/// let u = source.add_vertex();
|
||||||
|
/// let v = source.add_vertex();
|
||||||
|
/// let e = source.add_edge(u, v);
|
||||||
|
/// let (graph, vertex_map, edge_map) = FrozenGraph::from_graph(&source);
|
||||||
|
///
|
||||||
|
/// assert!(graph.are_adjacent(vertex_map[u], vertex_map[v]));
|
||||||
|
/// ```
|
||||||
|
fn from_graph<G: GraphTopology>(
|
||||||
|
source: &G,
|
||||||
|
) -> (
|
||||||
|
Self,
|
||||||
|
ElementMap<G::Vertex, Self::Vertex>,
|
||||||
|
ElementMap<G::Edge, Self::Edge>,
|
||||||
|
)
|
||||||
|
where
|
||||||
|
Self: Sized;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user