Expand description
Hexagonal lattice constructor (ALGO-CN-024).
Counterpart of igraph_hexagonal_lattice() in
references/igraph/src/constructors/lattices.c:572-616.
Builds a planar hexagonal (honeycomb) lattice whose vertices have
coordinates (i, j) for non-negative integers, with (i, j) joined
to (i + 1, j) and (when i is odd) also to (i - 1, j + 1). The
graph is the planar dual of crate::triangular_lattice:
1:1 correspondence between length-6 cycles here and triangles there.
Every vertex has degree at most 3.
The dims slice doubles as a shape selector with three modes:
[n]— triangular outline,nhexagons per side[size_x, size_y]— quasi-rectangle,size_x × size_yhexagons[size_x, size_y, size_z]— hexagonal outline with the three sides carryingsize_x,size_y,size_zhexagons respectively
Vertices are numbered lexicographically with the second coordinate
more significant, matching the upstream lex_ordering = false path.
Modes:
directed = false: every undirected lattice edge is emitted once.directed = true, mutual = false: each lattice edge becomes a single arc from the lower id to the higher.directed = true, mutual = true: every undirected lattice edge becomes a pair of opposite arcs.
Special cases:
- Any
dims[k] == 0→ empty graph (upstreamigraph_vector_int_any_smaller(dims, 1)guard). dims.len() != 1, 2, 3→IgraphError::InvalidArgument.
Algorithm: byte-for-byte port of upstream’s three private shape
helpers (hexagonal_lattice_triangle_shape /
hexagonal_lattice_rectangle_shape / hexagonal_lattice_hex_shape)
followed by the shared hexagonal_lattice emitter, which walks
every site and emits the two candidate forward neighbours (right,
and — only for odd k — up-left).
Time complexity: O(|V| + |E|).
Functions§
- hexagonal_
lattice - Build a hexagonal (honeycomb) lattice with the requested shape.