Skip to main content

count_mutual

Function count_mutual 

Source
pub fn count_mutual(graph: &Graph, loops: bool) -> IgraphResult<usize>
Expand description

Count the number of mutual edge pairs in a directed graph.

Each pair of reciprocal edges (A→B and B→A) is counted once. Self-loops are counted if loops is true.

For undirected graphs, returns the number of edges (all are mutual).

§Examples

use rust_igraph::{Graph, count_mutual};

let mut g = Graph::new(4, true).unwrap();
g.add_edge(0, 1).unwrap();
g.add_edge(1, 0).unwrap();
g.add_edge(1, 2).unwrap();
g.add_edge(2, 1).unwrap();
g.add_edge(2, 3).unwrap();
assert_eq!(count_mutual(&g, false).unwrap(), 2);