Skip to main content

hamming

Function hamming 

Source
pub fn hamming(n: u32, q: u32, directed: bool) -> IgraphResult<Graph>
Expand description

Build the d-dimensional Hamming graph H(n, q).

Returns a graph with q^n vertices where two vertices share an edge iff their base-q digit representations differ in exactly one position. For the directed variant every edge points from the lower-indexed endpoint to the higher-indexed one (the canonical orientation used by upstream igraph).

§Edge cases

  • n = 0 returns the singleton (one vertex, zero edges), regardless of q.
  • n > 0 and q = 0 returns the null graph (zero vertices, zero edges).
  • q = 1 returns the singleton.
  • q = 2 produces Q_n, equivalent to crate::hypercube.

§Errors

§Examples

use rust_igraph::hamming;

// H(2, 3) — 9 vertices, 18 edges, 4-regular.
let g = hamming(2, 3, false).unwrap();
assert_eq!(g.vcount(), 9);
assert_eq!(g.ecount(), 18);