pub fn count_adjacent_triangles(graph: &Graph) -> IgraphResult<Vec<u64>>Expand description
Per-vertex adjacent-triangle count. Entry i is the number of
triangles vertex i participates in. Parallel edges and self-loops
are ignored — the simple graph induced by the OUT-neighbour view is
used (consistent with count_triangles). For directed graphs that
is not yet the underlying-undirected projection that upstream uses;
see ALGO-PR-002 for the deferred fix.
Counterpart of igraph_count_adjacent_triangles() from
references/igraph/src/properties/triangles.c:522. Always runs the
“all vertices” path (adjacent_triangles4); the C version’s
per-vertex adjacent_triangles1 short-circuit is moot when querying
every vertex.
Invariants: result.iter().sum::<u64>() == 3 * count_triangles(g),
and each entry is bounded by C(deg, 2).
§Examples
use rust_igraph::{Graph, count_adjacent_triangles};
// K4: every vertex sees the 3 triangles meeting at it.
let mut g = Graph::with_vertices(4);
for u in 0..4u32 {
for v in (u + 1)..4 {
g.add_edge(u, v).unwrap();
}
}
assert_eq!(count_adjacent_triangles(&g).unwrap(), vec![3, 3, 3, 3]);
// Star centre meets 0 triangles; leaves all 0 as well.
let mut g = Graph::with_vertices(4);
for v in 1..4 { g.add_edge(0, v).unwrap(); }
assert_eq!(count_adjacent_triangles(&g).unwrap(), vec![0, 0, 0, 0]);