Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::Build_Grid< GT, Operation_On_Node, Operation_On_Arc > Class Template Reference

Functor to build a 2D grid graph with 8-connectivity. More...

#include <grid.H>

Public Member Functions

void operator() (GT &g, const size_t &width, const size_t &height)
 Build a grid graph.
 

Detailed Description

template<class GT, class Operation_On_Node = Default_Operation_On_Node<GT>, class Operation_On_Arc = Default_Operation_On_Arc<GT>>
class Aleph::Build_Grid< GT, Operation_On_Node, Operation_On_Arc >

Functor to build a 2D grid graph with 8-connectivity.

Creates a rectangular grid of nodes where each node is connected to all its neighbors: left, right, up, down, and all four diagonals.

Template Parameters
GTGraph type (e.g., List_Graph, Array_Graph)
Operation_On_NodeCallback for node initialization
Operation_On_ArcCallback for arc initialization

Complexity

  • Time: O(width × height)
  • Space: O(width × height) for nodes

Node Connectivity

Position Connections
Corner 3
Edge 5
Interior 8
Example
// Create grid with custom weight initialization
struct WeightArc {
void operator()(Graph& g, Arc* a, size_t i, size_t j) {
a->get_info() = 1.0; // Unit weight
}
};
Build_Grid<decltype(g), Default_Operation_On_Node<decltype(g)>, WeightArc> builder;
builder(g, 5, 5);
WeightedDigraph::Arc Arc
DynList< T > maps(const C &c, Op op)
Classic map operation.
Author
Alejandro Mujica

Definition at line 164 of file grid.H.

Member Function Documentation

◆ operator()()

template<class GT , class Operation_On_Node = Default_Operation_On_Node<GT>, class Operation_On_Arc = Default_Operation_On_Arc<GT>>
void Aleph::Build_Grid< GT, Operation_On_Node, Operation_On_Arc >::operator() ( GT g,
const size_t width,
const size_t height 
)
inline

Build a grid graph.

Creates a width × height grid of nodes with 8-connectivity.

Parameters
gGraph to populate (must be empty)
widthNumber of columns (≥ 2)
heightNumber of rows (≥ 2)
Exceptions
std::domain_errorif graph is not empty
std::length_errorif width or height < 2
Postcondition
g contains width*height nodes with grid connectivity

Definition at line 182 of file grid.H.

References ah_domain_error_if, ah_length_error_if, Aleph::clear_graph(), GraphCommon< GT, Node, Arc >::get_num_nodes(), Aleph::List_Graph< _Graph_Node, _Graph_Arc >::insert_arc(), Aleph::List_Graph< _Graph_Node, _Graph_Arc >::insert_node(), and Aleph::maps().


The documentation for this class was generated from the following file: