Add generators::path, without tests
This commit is contained in:
@@ -44,6 +44,23 @@ where
|
||||
)
|
||||
}
|
||||
|
||||
/// Generates a path graph.
|
||||
///
|
||||
/// Generates a path with `n` edges in `graph` as a new connected component and returns the new
|
||||
/// vertices *v0, v1, ..., vn* and edges *e0, e1, ..., e(n - 1)* in order, i.e. *e0 = (v0, v1)*,
|
||||
/// *e1 = (v1, v2)*, etc.
|
||||
///
|
||||
/// For `n == 0`, only a single vertex and no edges are added.
|
||||
pub fn path<G: GraphTopologyAddition>(graph: &mut G, n: usize) -> (Vec<G::Vertex>, Vec<G::Edge>) {
|
||||
graph.reserve_vertices(n + 1);
|
||||
graph.reserve_edges(n);
|
||||
let vertices: Vec<_> = (0..n + 1).map(|_| graph.add_vertex()).collect();
|
||||
let edges = (0..n)
|
||||
.map(|i| graph.add_edge(vertices[i], vertices[i + 1]))
|
||||
.collect();
|
||||
(vertices, edges)
|
||||
}
|
||||
|
||||
/// Generates a Petersen graph.
|
||||
///
|
||||
/// Generates a [Petersen graph] in `graph` as a new connected component and returns the new
|
||||
|
||||
Reference in New Issue
Block a user