diff --git a/src/generators.rs b/src/generators.rs index 16cf936..16d2bec 100644 --- a/src/generators.rs +++ b/src/generators.rs @@ -46,16 +46,19 @@ 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. +/// Generates a [path graph] *P(n)* with `n` vertices and `n - 1` edges in `graph` as a new +/// connected component and returns the new vertices *v0, v1, ..., v(n - 1)* and edges +/// *e0, e1, ..., e(n - 2)* in order, i.e. *e0 = (v0, v1)*, *e1 = (v1, v2)*, etc. and *v0* and +/// *v(n-1)* being the two terminal vertices /// -/// For `n == 0`, only a single vertex and no edges are added. +/// For `n == 0`, nothing is added. For `n == 1`, only a single vertex and no edges are added. +/// +/// [Path graph]: https://en.wikipedia.org/wiki/Path_graph pub fn path(graph: &mut G, n: usize) -> (Vec, Vec) { - graph.reserve_vertices(n + 1); - graph.reserve_edges(n); - let vertices: Vec<_> = (0..n + 1).map(|_| graph.add_vertex()).collect(); - let edges = (0..n) + graph.reserve_vertices(n); + graph.reserve_edges(n - 1); + let vertices: Vec<_> = (0..n).map(|_| graph.add_vertex()).collect(); + let edges = (0..n - 1) .map(|i| graph.add_edge(vertices[i], vertices[i + 1])) .collect(); (vertices, edges)