Skip to main content

de_bruijn

Function de_bruijn 

Source
pub fn de_bruijn(m: u32, n: u32) -> IgraphResult<Graph>
Expand description

Build the De Bruijn graph B(m, n).

The result is always directed, matches the C convention (IGRAPH_DIRECTED). Self-loops appear naturally whenever the rewrite (i, ((i * m) mod m^n) + b) lands back on i — most notably for m == 1, n ≥ 1, where the single vertex 0 has a self-loop, and along the main diagonal of B(m, 1).

§Errors

  • IgraphError::InvalidArgumentm.pow(n) would overflow u32 (vertex count too large to address with the graph’s u32 vertex id width). The check uses u32::checked_pow so the failure mode is deterministic and never produces a silently-wrapped graph.
  • IgraphError::InvalidArgument — the edge count m^(n+1) overflows usize so the edge buffer cannot be sized safely.

§Examples

use rust_igraph::de_bruijn;

// B(2, 2) — 4 vertices, 8 arcs, 4 of which are self-loops or pairs.
let g = de_bruijn(2, 2).unwrap();
assert_eq!(g.vcount(), 4);
assert_eq!(g.ecount(), 8);
assert!(g.is_directed());