Skip to main content

hexagonal_lattice

Function hexagonal_lattice 

Source
pub fn hexagonal_lattice(
    dims: &[u32],
    directed: bool,
    mutual: bool,
) -> IgraphResult<Graph>
Expand description

Build a hexagonal (honeycomb) lattice with the requested shape.

See the module documentation for the meaning of dims, directed, and mutual.

§Errors

  • IgraphError::InvalidArgument — when:
    • dims.len() is not in {1, 2, 3} (upstream IGRAPH_EINVAL: "size of the dimension vector must be 1, 2 or 3"),
    • the implied vertex or edge count overflows u32.

The upstream “negative dimension” path is eliminated at the type level by taking &[u32].

§Examples

use rust_igraph::hexagonal_lattice;

// dims=[1] — a single hexagon: 6 vertices forming C_6 with 6 edges.
let g = hexagonal_lattice(&[1], false, false).unwrap();
assert_eq!(g.vcount(), 6);
assert_eq!(g.ecount(), 6);

// 2 x 2 quasi-rectangle from python-igraph testHexagonalLattice.
let g = hexagonal_lattice(&[2, 2], false, false).unwrap();
assert_eq!(g.vcount(), 16);
assert_eq!(g.ecount(), 19);

// Zero in any dim collapses to the empty graph.
let g = hexagonal_lattice(&[3, 0], false, false).unwrap();
assert_eq!(g.vcount(), 0);