|
numerics 0.1.0
|
include/spatial/connected_components.hpp provides num::connected_components, a template BFS labelling function with a pre-allocated flat queue (no heap allocation per call, no recursion).
The Ising nucleation app needed BFS over spin-down clusters to identify the largest nucleus for umbrella sampling. The original ClusterDetector struct embedded the queue, the id array, and the BFS logic together – 45 lines of app-specific code that is, in fact, a general graph algorithm.
connected_components extracts the algorithm into the library with a callable-based interface that costs nothing at runtime (no std::function).
id[i] | Meaning |
|---|---|
-2 | Excluded – in_cluster(i) returned false |
>=0 | Cluster index |
Sites with id[i] == ClusterResult::largest_id belong to the largest cluster.
Iterative BFS with a pre-allocated flat queue of size n_sites:
No heap allocations after the initial ClusterResult construction.
Used by: Ising IsingLattice::sweep_umbrella.
The callable interface accepts any graph topology – not just 2D lattices: