Skip to main content

is_complete

Function is_complete 

Source
pub fn is_complete(graph: &Graph) -> IgraphResult<bool>
Expand description

Returns true iff every pair of distinct vertices is adjacent.

The null graph (n == 0) and the singleton graph (n == 1) are considered complete (matches igraph_is_complete).

On directed graphs both directions must be present for every pair (u, v) with u != v — this matches upstream’s igraph_neighbors(_, _, _, IGRAPH_OUT, NO_LOOPS, NO_MULTIPLE) counting and igraph_is_simple(_, _, IGRAPH_DIRECTED) short-circuit.

Counterpart of igraph_is_complete from references/igraph/src/properties/complete.c:43.

§Examples

use rust_igraph::{Graph, is_complete};

// Null graph — vacuously complete.
let g = Graph::with_vertices(0);
assert!(is_complete(&g).unwrap());

// K_3 — every pair adjacent.
let mut g = Graph::with_vertices(3);
g.add_edges(vec![(0u32, 1u32), (0, 2), (1, 2)]).unwrap();
assert!(is_complete(&g).unwrap());

// Path P_3 (0-1-2) — 0 and 2 not adjacent.
let mut g = Graph::with_vertices(3);
g.add_edges(vec![(0u32, 1u32), (1, 2)]).unwrap();
assert!(!is_complete(&g).unwrap());