|
Aleph-w 7.10.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. | |
| Dense_Cell_Storage (const Dense_Cell_Storage &other)=default | |
Copy another storage: its extents and its cells, which the copy keeps apart from those of other. | |
| Dense_Cell_Storage (Dense_Cell_Storage &&other) noexcept | |
| Take the cells of another storage, which is left empty. | |
| Dense_Cell_Storage & | operator= (const Dense_Cell_Storage &other)=default |
Copy another storage into this one: its extents and its cells, which this one keeps apart from those of other. | |
| Dense_Cell_Storage & | operator= (Dense_Cell_Storage &&other) noexcept |
| Exchange this storage with another, which is left with the previous cells of this one. | |
| 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 312 of file tpl_ca_storage.H.
| using Aleph::CA::Dense_Cell_Storage< T, N >::coord_type = Coord_Vec<N> |
Definition at line 104 of file tpl_ca_storage.H.
| using Aleph::CA::Dense_Cell_Storage< T, N >::extents_type = std::array<ca_size_t, N> |
Definition at line 105 of file tpl_ca_storage.H.
| using Aleph::CA::Dense_Cell_Storage< T, N >::state_type = T |
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 309 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.
|
default |
Copy another storage: its extents and its cells, which the copy keeps apart from those of other.
| [in] | other | storage to copy. |
|
inlinenoexcept |
Take the cells of another storage, which is left empty.
The implicit move took the buffer but copied the extents: the moved-from storage then indexed a buffer that it no longer had.
| [in,out] | other | storage to move from. |
Definition at line 160 of file tpl_ca_storage.H.
|
inline |
1D shorthand for at({i}).
Definition at line 255 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 262 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 269 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 239 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 303 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 297 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 Moved_From_Case< Dense_Cell_Storage< int, 2 > >::is_empty(), 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 184 of file tpl_ca_storage.H.
References N.
Referenced by TEST().
|
inlinenoexcept |
Definition at line 206 of file tpl_ca_storage.H.
References Aleph::CA::Dense_Cell_Storage< T, N >::ext_.
Referenced by Moved_From_Case< Dense_Cell_Storage< int, 2 > >::fingerprint(), TEST(), and Moved_From_Case< Dense_Cell_Storage< int, 2 > >::use().
|
inline |
Set every cell to value.
Definition at line 360 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.
Referenced by Moved_From_Case< Dense_Cell_Storage< int, 2 > >::use().
|
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 221 of file tpl_ca_storage.H.
References ah_out_of_range_error_if, 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().
|
default |
Copy another storage into this one: its extents and its cells, which this one keeps apart from those of other.
| [in] | other | storage to copy. |
|
inlinenoexcept |
Exchange this storage with another, which is left with the previous cells of this one.
| [in,out] | other | storage to move from. |
Definition at line 177 of file tpl_ca_storage.H.
References Aleph::CA::Dense_Cell_Storage< T, N >::swap().
|
inlinestaticprivate |
Definition at line 115 of file tpl_ca_storage.H.
References ah_overflow_error_if, Aleph::and, and N.
|
inline |
3D shorthand for set({i, j, k}, v).
Definition at line 290 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 283 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 276 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 249 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 190 of file tpl_ca_storage.H.
References Aleph::CA::Dense_Cell_Storage< T, N >::total_cells_.
Referenced by Moved_From_Case< Dense_Cell_Storage< int, 2 > >::fingerprint(), Moved_From_Case< Dense_Cell_Storage< int, 2 > >::is_empty(), TEST(), TEST(), TEST(), and Moved_From_Case< Dense_Cell_Storage< int, 2 > >::use().
|
inline |
Extent of axis d.
| [in] | d | axis index in [0, N). |
| std::out_of_range | if d >= N. |
Definition at line 199 of file tpl_ca_storage.H.
References ah_out_of_range_error_if, and Aleph::CA::Dense_Cell_Storage< T, N >::ext_.
|
inlinenoexcept |
O(1) swap with another storage of the same type.
Definition at line 351 of file tpl_ca_storage.H.
References 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 >::operator=(), and 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 345 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 336 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(), TEST(), and Moved_From_Case< Dense_Cell_Storage< int, 2 > >::use().
|
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().