Skip to main content

count_multiple

Function count_multiple 

Source
pub fn count_multiple(graph: &Graph) -> IgraphResult<Vec<usize>>
Expand description

Per-edge multiplicity: how many edges share each edge’s endpoint pair.

result[e] is the number of edges e' (including e itself) whose endpoint pair matches e’s. Storage already canonicalises undirected pairs to (min, max), so undirected (a,b) and (b,a) collapse to the same group; directed pairs are kept ordered.

Self-loops at the same vertex group together — each such loop has multiplicity equal to the number of loops at that vertex (matching upstream’s IGRAPH_LOOPS_ONCE lazy-adjlist semantics).

Counterpart of igraph_count_multiple() from references/igraph/src/properties/multiplicity.c.

O(|E| log |E|) via sort-and-group over stored edges.

§Examples

use rust_igraph::{Graph, count_multiple};

let mut g = Graph::with_vertices(3);
g.add_edge(0, 1).unwrap();
g.add_edge(0, 1).unwrap();
g.add_edge(1, 2).unwrap();
// Edge 0 and edge 1 share (0,1) → multiplicity 2 each.
// Edge 2 is alone → multiplicity 1.
assert_eq!(count_multiple(&g).unwrap(), vec![2, 2, 1]);