57#ifndef TPL_CA_LATTICE_H
58#define TPL_CA_LATTICE_H
73namespace ca_lattice_detail {
79 return static_cast<ca_size_t>(-(c + 1)) + 1;
93 return r == 0 ? 0 : n -
r;
104 if (n > (std::numeric_limits<ca_size_t>::max() >> 1))
105 return c >= 0 ?
mag :
mag - 1;
114 r = mod == 0 ? 0 :
period - mod;
128template <
typename T, T V>
147template <
typename Storage,
typename Boundary = OpenBoundary>
157 static constexpr std::size_t
rank = Storage::rank;
164 if constexpr (ca_lattice_detail::is_constant_boundary_v<Boundary>)
165 return static_cast<state_type>(Boundary::value);
176 using namespace ca_lattice_detail;
177 for (std::size_t d = 0; d <
rank; ++d)
183 if constexpr (std::is_same_v<Boundary, ToroidalBoundary>)
185 c[d] =
static_cast<ca_index_t>(wrap_into_range(c[d], n));
187 else if constexpr (std::is_same_v<Boundary, ReflectiveBoundary>)
189 c[d] =
static_cast<ca_index_t>(reflect_into_range(c[d], n));
191 else if constexpr (std::is_same_v<Boundary, NeumannBoundary>)
196 else if (
static_cast<ca_size_t>(c[d]) >= n)
222 explicit Lattice(
Storage &&s)
noexcept(std::is_nothrow_move_constructible_v<Storage>)
308template <
typename Storage,
typename Boundary>
Exception handling system with formatted messages for Aleph-w.
size_t size_t int32_t value
Common typedefs and tag types for the Cellular Automata module.
Lattice that adds boundary-aware access on top of a storage.
state_type at_safe(coord_type c) const
Boundary-aware read.
void set(const coord_type &c, const state_type &v)
Strict write: throws if c is out of range.
typename Storage::state_type state_type
Lattice(const extents_type &extents, const state_type &init=state_type{})
Construct a lattice with the given extents and initial value.
typename Storage::extents_type extents_type
const extents_type & extents() const noexcept
void swap(Lattice &other) noexcept(noexcept(store_.swap(other.store_)))
O(1) swap.
typename Storage::coord_type coord_type
Storage & storage() noexcept
Direct read-write access to the underlying storage.
ca_size_t size(std::size_t d) const
static constexpr std::size_t rank
ca_size_t size() const noexcept
const Storage & storage() const noexcept
Direct read access to the underlying storage (read-only).
bool fold_coord(coord_type &c) const
Try to fold c into a valid in-range coordinate using the boundary policy.
void fill(const state_type &value)
Set every cell to value.
static constexpr std::size_t dimension() noexcept
state_type out_of_range_value() const
Lattice()=default
Construct an empty lattice (no cells allocated).
state_type at(const coord_type &c) const
Strict access: throws if c is out of range.
Lattice(Storage &&s) noexcept(std::is_nothrow_move_constructible_v< Storage >)
Wrap an existing storage by move.
Shape (per-axis sizes) of an mdspan, mixing compile-time and run-time extents.
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
ca_size_t reflect_into_range(const ca_index_t c, const ca_size_t n) noexcept
Reflect a signed coordinate into [0, n) (no-repeat triangle wave).
ca_size_t magnitude(const ca_index_t c) noexcept
ca_size_t wrap_into_range(ca_index_t c, const ca_size_t n) noexcept
Wrap a signed coordinate into [0, n) with positive modulo.
constexpr bool is_constant_boundary_v
std::ptrdiff_t ca_index_t
Signed coordinate component used by lattices and neighborhoods.
void swap(Bit_Cell_Storage< N > &a, Bit_Cell_Storage< N > &b) noexcept
Free-function swap so the storage plays nicely with std::swap.
std::size_t ca_size_t
Unsigned size component used for extents and counts.
Main namespace for Aleph-w library functions.
std::decay_t< typename HeadC::Item_Type > T
static std::atomic< bool > init
True iff B is a ConstantBoundary<T, V>.
C++20 concepts for the Cellular Automata module.