pub fn difference(orig: &Graph, sub: &Graph) -> IgraphResult<Graph>Expand description
Returns orig \ sub: the multiset difference of the edges.
The result has orig.vcount() vertices — vertices in sub beyond
orig.vcount() are simply ignored. For each endpoint pair (u, v),
the multiplicity in the result equals
max(0, count_orig - count_sub).
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
IgraphError::InvalidArgumentif directedness diverges.
§Examples
use rust_igraph::{Graph, difference};
// Triangle \ path: edges {(0,1), (1,2), (2,0)} \ {(0,1), (1,2)}
// → {(0,2)} on 3 vertices (canonicalised (0,2) for undirected).
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(3);
b.add_edge(0, 1).unwrap();
b.add_edge(1, 2).unwrap();
let d = difference(&a, &b).unwrap();
assert_eq!(d.vcount(), 3);
assert_eq!(d.ecount(), 1);