|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Row-major dense storage for N-dimensional cellular automata.
More...
#include <tpl_ca_storage.H>
Public Types | |
| using | state_type = T |
| using | coord_type = Coord_Vec< N > |
| using | extents_type = std::array< ca_size_t, N > |
| using | view_type = Aleph::mdspan< T, Aleph::dextents< ca_size_t, N > > |
Non-owning, zero-copy N-dimensional view of this storage's buffer. | |
| using | const_view_type = Aleph::mdspan< const T, Aleph::dextents< ca_size_t, N > > |
Non-owning, zero-copy read-only N-dimensional view of this storage's buffer. | |
Public Member Functions | |
| Dense_Cell_Storage ()=default | |
| Construct an empty storage (zero extents, no cells allocated). | |
| Dense_Cell_Storage (const extents_type &extents, const T &init=T{}) | |
| Construct a storage with the given extents and initial value. | |
| ca_size_t | size () const noexcept |
| ca_size_t | size (std::size_t d) const |
Extent of axis d. | |
| const extents_type & | extents () const noexcept |
| ca_size_t | linear_index (const coord_type &c) const |
| Map a multi-index to a linear offset. | |
| T | at (const coord_type &c) const |
| Read access through a multi-index. | |
| void | set (const coord_type &c, const T &v) |
| Write access through a multi-index. | |
| T | at (ca_index_t i) const |
1D shorthand for at({i}). | |
| T | at (ca_index_t i, ca_index_t j) const |
2D shorthand for at({i, j}). | |
| T | at (ca_index_t i, ca_index_t j, ca_index_t k) const |
3D shorthand for at({i, j, k}). | |
| void | set (ca_index_t i, const T &v) |
1D shorthand for set({i}, v). | |
| void | set (ca_index_t i, ca_index_t j, const T &v) |
2D shorthand for set({i, j}, v). | |
| void | set (ca_index_t i, ca_index_t j, ca_index_t k, const T &v) |
3D shorthand for set({i, j, k}, v). | |
| T * | data () noexcept |
| const T * | data () const noexcept |
| view_type | view () noexcept |
Return a mutable Aleph::mdspan view of this storage. | |
| const_view_type | view () const noexcept |
| void | swap (Dense_Cell_Storage &other) noexcept |
| O(1) swap with another storage of the same type. | |
| void | fill (const T &value) |
Set every cell to value. | |
Static Public Member Functions | |
| static constexpr std::size_t | dimension () noexcept |
Static Public Attributes | |
| static constexpr std::size_t | rank = N |
| Number of axes known at compile time. | |
Static Private Member Functions | |
| static ca_size_t | product (const extents_type &e) |
Private Attributes | |
| extents_type | ext_ {} |
| per-axis extents | |
| ca_size_t | total_cells_ = 0 |
product of ext | |
| Array< T > | buffer_ |
| contiguous row-major storage | |
Row-major dense storage for N-dimensional cellular automata.
Stores extents()[0] * extents()[1] * ... * extents()[N-1] cells of type T in a single contiguous buffer. Indexing is row-major (axis N-1 varies fastest), matching the convention of C arrays and of al-matrix.H.
The class satisfies the CA::LatticeLike concept directly: it exposes dimension(), size(d), at(coord) and set(coord, v). Higher-level boundary handling is layered on top by Lattice<Storage, Boundary> in tpl_ca_lattice.H.
| T | cell state type. Must satisfy CA::CellState. |
| N | number of axes (1, 2 or 3 are the typical values). |
at, set, linear_index, data, size, extents, view: O(1).swap: O(1) (swaps the internal Array<T> pointers).fill: O(size()).Definition at line 97 of file tpl_ca_storage.H.
| using Aleph::CA::Dense_Cell_Storage< T, N >::const_view_type = Aleph::mdspan<const T, Aleph::dextents<ca_size_t, N> > |
Non-owning, zero-copy read-only N-dimensional view of this storage's buffer.
Definition at line 276 of file tpl_ca_storage.H.
Definition at line 104 of file tpl_ca_storage.H.
Definition at line 105 of file tpl_ca_storage.H.
Definition at line 103 of file tpl_ca_storage.H.
| using Aleph::CA::Dense_Cell_Storage< T, N >::view_type = Aleph::mdspan<T, Aleph::dextents<ca_size_t, N> > |
Non-owning, zero-copy N-dimensional view of this storage's buffer.
Definition at line 273 of file tpl_ca_storage.H.
|
default |
Construct an empty storage (zero extents, no cells allocated).
|
inlineexplicit |
Construct a storage with the given extents and initial value.
Allocates and value-initialises prod(extents) cells of type T, each set to init.
| [in] | extents | per-axis sizes. |
| [in] | init | initial value for every cell (default: T{}). |
| std::bad_alloc | on allocation failure. |
Definition at line 143 of file tpl_ca_storage.H.
|
inline |
1D shorthand for at({i}).
Definition at line 219 of file tpl_ca_storage.H.
References Aleph::CA::Dense_Cell_Storage< T, N >::at().
|
inline |
2D shorthand for at({i, j}).
Definition at line 226 of file tpl_ca_storage.H.
References Aleph::CA::Dense_Cell_Storage< T, N >::at().
|
inline |
3D shorthand for at({i, j, k}).
Definition at line 233 of file tpl_ca_storage.H.
References Aleph::CA::Dense_Cell_Storage< T, N >::at(), and k.
|
inline |
Read access through a multi-index.
| [in] | c | multi-index, in range. |
c. | std::out_of_range | if c is out of range. |
Definition at line 203 of file tpl_ca_storage.H.
References Aleph::CA::Dense_Cell_Storage< T, N >::buffer_, and Aleph::CA::Dense_Cell_Storage< T, N >::linear_index().
Referenced by Aleph::CA::Dense_Cell_Storage< T, N >::at(), Aleph::CA::Dense_Cell_Storage< T, N >::at(), Aleph::CA::Dense_Cell_Storage< T, N >::at(), and TEST().
|
inlinenoexcept |
nullptr if empty). Definition at line 267 of file tpl_ca_storage.H.
References Aleph::CA::Dense_Cell_Storage< T, N >::buffer_, and Aleph::CA::Dense_Cell_Storage< T, N >::total_cells_.
|
inlinenoexcept |
nullptr if empty). Definition at line 261 of file tpl_ca_storage.H.
References Aleph::CA::Dense_Cell_Storage< T, N >::buffer_, and Aleph::CA::Dense_Cell_Storage< T, N >::total_cells_.
Referenced by TEST(), TEST(), TEST(), TEST(), Aleph::CA::Dense_Cell_Storage< T, N >::view(), and Aleph::CA::Dense_Cell_Storage< T, N >::view().
|
inlinestaticconstexprnoexcept |
Definition at line 148 of file tpl_ca_storage.H.
References N.
Referenced by TEST().
|
inlinenoexcept |
Definition at line 170 of file tpl_ca_storage.H.
References Aleph::CA::Dense_Cell_Storage< T, N >::ext_.
Referenced by TEST().
Set every cell to value.
Definition at line 324 of file tpl_ca_storage.H.
References Aleph::CA::Dense_Cell_Storage< T, N >::buffer_, Aleph::CA::Dense_Cell_Storage< T, N >::total_cells_, and value.
|
inline |
Map a multi-index to a linear offset.
Layout is row-major: the last axis varies fastest. All components of c must be non-negative and within range; this method does the bounds check and throws on violation.
| [in] | c | multi-index. |
[0, size()). | std::out_of_range | if any component is out of range. |
Definition at line 185 of file tpl_ca_storage.H.
References ah_out_of_range_error_if, Aleph::blossom_maximum_cardinality_matching(), Aleph::CA::Dense_Cell_Storage< T, N >::ext_, and N.
Referenced by Aleph::CA::Dense_Cell_Storage< T, N >::at(), and Aleph::CA::Dense_Cell_Storage< T, N >::set().
|
inlinestaticprivate |
Definition at line 115 of file tpl_ca_storage.H.
References ah_overflow_error_if, Aleph::and, Aleph::blossom_maximum_cardinality_matching(), and N.
|
inline |
3D shorthand for set({i, j, k}, v).
Definition at line 254 of file tpl_ca_storage.H.
References k, and Aleph::CA::Dense_Cell_Storage< T, N >::set().
|
inline |
2D shorthand for set({i, j}, v).
Definition at line 247 of file tpl_ca_storage.H.
References Aleph::CA::Dense_Cell_Storage< T, N >::set().
|
inline |
1D shorthand for set({i}, v).
Definition at line 240 of file tpl_ca_storage.H.
References Aleph::CA::Dense_Cell_Storage< T, N >::set().
|
inline |
Write access through a multi-index.
| [in] | c | multi-index, in range. |
| [in] | v | new value. |
| std::out_of_range | if c is out of range. |
Definition at line 213 of file tpl_ca_storage.H.
References Aleph::CA::Dense_Cell_Storage< T, N >::buffer_, and Aleph::CA::Dense_Cell_Storage< T, N >::linear_index().
Referenced by Aleph::CA::Dense_Cell_Storage< T, N >::set(), Aleph::CA::Dense_Cell_Storage< T, N >::set(), Aleph::CA::Dense_Cell_Storage< T, N >::set(), TEST(), TEST(), TEST(), and TEST().
|
inlinenoexcept |
Definition at line 154 of file tpl_ca_storage.H.
References Aleph::CA::Dense_Cell_Storage< T, N >::total_cells_.
|
inline |
Extent of axis d.
| [in] | d | axis index in [0, N). |
| std::out_of_range | if d >= N. |
Definition at line 163 of file tpl_ca_storage.H.
References ah_out_of_range_error_if, Aleph::CA::Dense_Cell_Storage< T, N >::ext_, and N.
|
inlinenoexcept |
O(1) swap with another storage of the same type.
Definition at line 315 of file tpl_ca_storage.H.
References Aleph::blossom_maximum_cardinality_matching(), Aleph::CA::Dense_Cell_Storage< T, N >::buffer_, Aleph::CA::Dense_Cell_Storage< T, N >::ext_, Aleph::CA::Dense_Cell_Storage< T, N >::swap(), and Aleph::CA::Dense_Cell_Storage< T, N >::total_cells_.
Referenced by Aleph::CA::Dense_Cell_Storage< T, N >::swap().
|
inlinenoexcept |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 309 of file tpl_ca_storage.H.
References Aleph::CA::Dense_Cell_Storage< T, N >::data(), and Aleph::CA::Dense_Cell_Storage< T, N >::ext_.
|
inlinenoexcept |
Return a mutable Aleph::mdspan view of this storage.
The view is a pointer plus the current extents(): it aliases this object's buffer directly (no allocation, no copy). It is invalidated by anything that would also invalidate data() (e.g. swap() with another storage, or this being destroyed) but not by an in-place set()/fill()/at() through the original storage or through the view itself — both read and write the same cells.
Definition at line 300 of file tpl_ca_storage.H.
References Aleph::CA::Dense_Cell_Storage< T, N >::data(), and Aleph::CA::Dense_Cell_Storage< T, N >::ext_.
Referenced by TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), and TEST().
|
private |
contiguous row-major storage
Definition at line 113 of file tpl_ca_storage.H.
Referenced by Aleph::CA::Dense_Cell_Storage< T, N >::at(), Aleph::CA::Dense_Cell_Storage< T, N >::data(), Aleph::CA::Dense_Cell_Storage< T, N >::data(), Aleph::CA::Dense_Cell_Storage< T, N >::fill(), Aleph::CA::Dense_Cell_Storage< T, N >::set(), and Aleph::CA::Dense_Cell_Storage< T, N >::swap().
|
private |
per-axis extents
Definition at line 111 of file tpl_ca_storage.H.
Referenced by Aleph::CA::Dense_Cell_Storage< T, N >::extents(), Aleph::CA::Dense_Cell_Storage< T, N >::linear_index(), Aleph::CA::Dense_Cell_Storage< T, N >::size(), Aleph::CA::Dense_Cell_Storage< T, N >::swap(), Aleph::CA::Dense_Cell_Storage< T, N >::view(), and Aleph::CA::Dense_Cell_Storage< T, N >::view().
|
staticconstexpr |
Number of axes known at compile time.
Definition at line 108 of file tpl_ca_storage.H.
Referenced by TEST().
|
private |
product of ext
Definition at line 112 of file tpl_ca_storage.H.
Referenced by Aleph::CA::Dense_Cell_Storage< T, N >::data(), Aleph::CA::Dense_Cell_Storage< T, N >::data(), Aleph::CA::Dense_Cell_Storage< T, N >::fill(), Aleph::CA::Dense_Cell_Storage< T, N >::size(), and Aleph::CA::Dense_Cell_Storage< T, N >::swap().