pub fn star_graph<G, T, F, H, M>(
num_nodes: Option<usize>,
weights: Option<Vec<T>>,
default_node_weight: F,
default_edge_weight: H,
inward: bool,
bidirectional: bool,
) -> Result<G, InvalidInputError>
Expand description
Generate a star graph
Arguments:
num_nodes
- The number of nodes to create a star graph for. Either this orweights
must be specified. If both this andweights
are specified, weights will take priority and this argument will be ignoredweights
- AVec
of node weight objects.default_node_weight
- A callable that will return the weight to use for newly created nodes. This is ignored ifweights
is specified.default_edge_weight
- A callable that will return the weight object to use for newly created edges.inward
- If settrue
the nodes will be directed towards the center node. This parameter is ignored ifbidirectional
is set totrue
.bidirectional
- Whether edges are added bidirectionally. If set totrue
then for any edge(u, v)
an edge(v, u)
will also be added. If the graph is undirected this will result in a parallel edge.
ยงExample
use rustworkx_core::petgraph;
use rustworkx_core::generators::star_graph;
use rustworkx_core::petgraph::visit::EdgeRef;
let g: petgraph::graph::UnGraph<(), ()> = star_graph(
Some(4),
None,
|| {()},
|| {()},
false,
false
).unwrap();
assert_eq!(
vec![(0, 1), (0, 2), (0, 3)],
g.edge_references()
.map(|edge| (edge.source().index(), edge.target().index()))
.collect::<Vec<(usize, usize)>>(),
)