Skip to main content

list_triangles

Function list_triangles 

Source
pub fn list_triangles(graph: &Graph) -> IgraphResult<Vec<(u32, u32, u32)>>
Expand description

List all triangles in a graph.

Returns a vector of (u, v, w) triples where each triple represents a triangle. Each triangle is listed exactly once. Edge directions and multi-edges are ignored.

Uses degree-ordering to ensure each triangle is counted once: for each edge (u, v) where rank(u) > rank(v), checks neighbors of v that are also neighbors of u.

ยงExamples

use rust_igraph::{Graph, list_triangles};

let mut g = Graph::with_vertices(4);
g.add_edge(0, 1).unwrap();
g.add_edge(1, 2).unwrap();
g.add_edge(2, 0).unwrap();
g.add_edge(2, 3).unwrap();
g.add_edge(3, 0).unwrap();

let tris = list_triangles(&g).unwrap();
assert_eq!(tris.len(), 2); // triangles: (0,1,2) and (0,2,3)