Skip to main content

circulant

Function circulant 

Source
pub fn circulant(n: u32, shifts: &[i64], directed: bool) -> IgraphResult<Graph>
Expand description

Build the circulant graph G(n, shifts).

The result is directed iff directed is true. The graph never contains self-loops or parallel edges; redundant or zero shifts are silently dropped per the normalisation rules described in the module-level docs.

§Errors

  • IgraphError::InvalidArgument — any individual shift cannot be represented as i64 (this only fires on negative inputs that would not round-trip, since the public type is unsigned).
  • IgraphError::InvalidArgumentn * |shifts| overflows usize so the edge buffer cannot be sized safely.

§Examples

use rust_igraph::circulant;

// C_6 — cycle on 6 vertices.
let g = circulant(6, &[1], false).unwrap();
assert_eq!(g.vcount(), 6);
assert_eq!(g.ecount(), 6);

// K_4 — complete graph via every distinct undirected shift.
let k4 = circulant(4, &[1, 2], false).unwrap();
assert_eq!(k4.vcount(), 4);
assert_eq!(k4.ecount(), 6); // 4*3/2