Skip to main content

hypercube

Function hypercube 

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

Build the n-dimensional hypercube graph Q_n.

Returns a graph on 2^n vertices where two vertices share an edge iff their zero-based IDs differ in exactly one bit. For the directed variant every edge points from the lower-indexed endpoint to the higher-indexed one (the canonical orientation also used by upstream igraph). For n = 0 the graph is the singleton; for n = 1 it is K_2.

§Errors

§Examples

use rust_igraph::hypercube;

// Q_3 — 8-vertex cube, 12 edges, every vertex has degree 3.
let g = hypercube(3, false).unwrap();
assert_eq!(g.vcount(), 8);
assert_eq!(g.ecount(), 12);