Skip to main content

union

Function union 

Source
pub fn union(left: &Graph, right: &Graph) -> IgraphResult<Graph>
Expand description

Returns the union of left and right.

Vertex sets are aligned by index — the result has max(left.vcount(), right.vcount()) vertices. For each endpoint pair (u, v), the multiplicity in the result equals the larger of the multiplicities in the two inputs.

Both inputs must agree on directedness; an undirected edge (u, v) is canonicalised to (min(u, v), max(u, v)) before counting, while directed edges are tallied as-is.

Output edges are emitted in lexicographic (src, tgt) order; two edges sharing the same canonicalised pair appear consecutively.

§Errors

§Examples

use rust_igraph::{Graph, union};

// Triangle ∪ path: edges {(0,1), (1,2), (2,0)} ∪ {(0,1), (1,3)}
// → {(0,1), (1,2), (2,0), (1,3)} on 4 vertices.
let mut a = Graph::with_vertices(3);
a.add_edge(0, 1).unwrap();
a.add_edge(1, 2).unwrap();
a.add_edge(2, 0).unwrap();
let mut b = Graph::with_vertices(4);
b.add_edge(0, 1).unwrap();
b.add_edge(1, 3).unwrap();

let u = union(&a, &b).unwrap();
assert_eq!(u.vcount(), 4);
assert_eq!(u.ecount(), 4);