Skip to main content

disjoint_union_many

Function disjoint_union_many 

Source
pub fn disjoint_union_many(graphs: &[&Graph]) -> IgraphResult<Graph>
Expand description

Disjoint union of any number of graphs (ALGO-OP-002b).

Counterpart of igraph_disjoint_union_many(). Vertices of the i-th graph are relabelled to start at Σ_{j<i} graphs[j].vcount(), preserving each input’s internal vertex / edge ordering.

All inputs must have the same directedness. The empty slice yields the null graph (vcount = 0, undirected). A single-graph input returns a clone of that graph.

§Errors

§Examples

use rust_igraph::{Graph, disjoint_union_many};

// Three triangles → 9-vertex graph with three disjoint triangles.
let mut t = Graph::with_vertices(3);
t.add_edge(0, 1).unwrap();
t.add_edge(1, 2).unwrap();
t.add_edge(2, 0).unwrap();
let u = disjoint_union_many(&[&t, &t, &t]).unwrap();
assert_eq!(u.vcount(), 9);
assert_eq!(u.ecount(), 9);
// Third triangle's last edge is `(2, 0)` shifted by 6. The
// undirected adjacency canonicalises to (min, max).
assert_eq!(u.edge(8).unwrap(), (6, 8));