Skip to main content

trussness

Function trussness 

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

Compute the trussness of every edge in an undirected graph.

Returns a Vec<u32> of length graph.ecount() where entry i is the trussness of edge i. Multigraphs are rejected with an error; self-loops are accepted and receive trussness 2.

Counterpart of igraph_trussness() from references/igraph/src/centrality/truss.cpp.

§Errors

  • IgraphError::Unsupported if the graph has parallel edges (multigraph).
  • IgraphError::InvalidArgument if the graph is directed.

§Examples

use rust_igraph::{Graph, trussness};

// K4 (complete graph on 4 vertices): every edge is in 2
// triangles → trussness = 4 for all 6 edges.
let mut g = Graph::with_vertices(4);
for u in 0..4u32 {
    for v in (u + 1)..4 {
        g.add_edge(u, v).unwrap();
    }
}
let t = trussness(&g).unwrap();
assert!(t.iter().all(|&x| x == 4));

// Triangle (K3): every edge is in 1 triangle → trussness = 3.
let mut g = Graph::with_vertices(3);
for (u, v) in [(0, 1), (0, 2), (1, 2)] {
    g.add_edge(u, v).unwrap();
}
let t = trussness(&g).unwrap();
assert!(t.iter().all(|&x| x == 3));

// Path 0-1-2: no triangles → trussness = 2 for both edges.
let mut g = Graph::with_vertices(3);
g.add_edge(0, 1).unwrap();
g.add_edge(1, 2).unwrap();
let t = trussness(&g).unwrap();
assert!(t.iter().all(|&x| x == 2));