Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::CA::Bit_Cell_Storage< N > Class Template Reference

Bit-packed row-major storage for N-dimensional binary CAs. More...

#include <tpl_ca_bit_storage.H>

Collaboration diagram for Aleph::CA::Bit_Cell_Storage< N >:
[legend]

Public Types

using state_type = bool
 
using coord_type = Coord_Vec< N >
 
using extents_type = std::array< ca_size_t, N >
 

Public Member Functions

 Bit_Cell_Storage ()=default
 Construct an empty storage (zero extents).
 
 Bit_Cell_Storage (const extents_type &extents, const bool init=false)
 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
 Return the extent (number of cells) along axis d.
 
const extents_type & extents () const noexcept
 Return the full extents array.
 
ca_size_t linear_index (const coord_type &c) const
 Map a multi-index to a linear bit offset (row-major).
 
bool at (const coord_type &c) const
 Read the cell at coordinate c.
 
void set (const coord_type &c, bool v)
 Write the cell at coordinate c.
 
bool at (ca_index_t i) const
 Read 1D cell at index i.
 
bool at (ca_index_t i, ca_index_t j) const
 Read 2D cell at (i, j).
 
bool at (ca_index_t i, ca_index_t j, ca_index_t k) const
 Read 3D cell at (i, j, k).
 
void set (ca_index_t i, bool v)
 Write 1D cell at index i.
 
void set (ca_index_t i, ca_index_t j, const bool v)
 Write 2D cell at (i, j).
 
void set (ca_index_t i, ca_index_t j, ca_index_t k, const bool v)
 Write 3D cell at (i, j, k).
 
void swap (Bit_Cell_Storage &other) noexcept
 Swap contents with another Bit_Cell_Storage instance.
 
void fill (const bool 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
 
BitArray buffer_
 bit-packed row-major storage
 

Detailed Description

template<std::size_t N>
class Aleph::CA::Bit_Cell_Storage< N >

Bit-packed row-major storage for N-dimensional binary CAs.

Stores cells as 1-bit values inside an Aleph::BitArray. Linear layout is row-major (axis N-1 varies fastest), identical to Dense_Cell_Storage<bool, N>. Reading and writing are done with bool to keep the API uniform.

Template Parameters
Nnumber of axes (1, 2 or 3 are the typical values).

Definition at line 75 of file tpl_ca_bit_storage.H.

Member Typedef Documentation

◆ coord_type

template<std::size_t N>
using Aleph::CA::Bit_Cell_Storage< N >::coord_type = Coord_Vec<N>

Definition at line 81 of file tpl_ca_bit_storage.H.

◆ extents_type

template<std::size_t N>
using Aleph::CA::Bit_Cell_Storage< N >::extents_type = std::array<ca_size_t, N>

Definition at line 82 of file tpl_ca_bit_storage.H.

◆ state_type

template<std::size_t N>
using Aleph::CA::Bit_Cell_Storage< N >::state_type = bool

Definition at line 80 of file tpl_ca_bit_storage.H.

Constructor & Destructor Documentation

◆ Bit_Cell_Storage() [1/2]

template<std::size_t N>
Aleph::CA::Bit_Cell_Storage< N >::Bit_Cell_Storage ( )
default

Construct an empty storage (zero extents).

◆ Bit_Cell_Storage() [2/2]

template<std::size_t N>
Aleph::CA::Bit_Cell_Storage< N >::Bit_Cell_Storage ( const extents_type &  extents,
const bool  init = false 
)
inlineexplicit

Construct a storage with the given extents and initial value.

Parameters
[in]extentsper-axis sizes.
[in]initinitial value for every cell (default false).

Definition at line 115 of file tpl_ca_bit_storage.H.

Member Function Documentation

◆ at() [1/4]

template<std::size_t N>
bool Aleph::CA::Bit_Cell_Storage< N >::at ( ca_index_t  i) const
inline

Read 1D cell at index i.

Parameters
ithe column coordinate.
Returns
true if the cell is set, false otherwise.
Exceptions
std::out_of_rangeif i is out of bounds.

Definition at line 194 of file tpl_ca_bit_storage.H.

References Aleph::CA::Bit_Cell_Storage< N >::at().

◆ at() [2/4]

template<std::size_t N>
bool Aleph::CA::Bit_Cell_Storage< N >::at ( ca_index_t  i,
ca_index_t  j 
) const
inline

Read 2D cell at (i, j).

Parameters
ithe row coordinate.
jthe column coordinate.
Returns
true if the cell is set, false otherwise.
Exceptions
std::out_of_rangeif the coordinate is out of bounds.

Definition at line 206 of file tpl_ca_bit_storage.H.

References Aleph::CA::Bit_Cell_Storage< N >::at().

◆ at() [3/4]

template<std::size_t N>
bool Aleph::CA::Bit_Cell_Storage< N >::at ( ca_index_t  i,
ca_index_t  j,
ca_index_t  k 
) const
inline

Read 3D cell at (i, j, k).

Parameters
ithe depth coordinate.
jthe row coordinate.
kthe column coordinate.
Returns
true if the cell is set, false otherwise.
Exceptions
std::out_of_rangeif the coordinate is out of bounds.

Definition at line 219 of file tpl_ca_bit_storage.H.

References Aleph::CA::Bit_Cell_Storage< N >::at(), and k.

◆ at() [4/4]

template<std::size_t N>
bool Aleph::CA::Bit_Cell_Storage< N >::at ( const coord_type &  c) const
inline

Read the cell at coordinate c.

Parameters
[in]cmulti-dimensional coordinate.
Returns
true if the cell is set, false otherwise.
Exceptions
std::out_of_rangeif any component of c is out of range.

Definition at line 174 of file tpl_ca_bit_storage.H.

References Aleph::CA::Bit_Cell_Storage< N >::buffer_, Aleph::CA::Bit_Cell_Storage< N >::linear_index(), and Aleph::BitArray::read_bit().

Referenced by Aleph::CA::Bit_Cell_Storage< N >::at(), Aleph::CA::Bit_Cell_Storage< N >::at(), and Aleph::CA::Bit_Cell_Storage< N >::at().

◆ dimension()

template<std::size_t N>
static constexpr std::size_t Aleph::CA::Bit_Cell_Storage< N >::dimension ( )
inlinestaticconstexprnoexcept
Returns
the number of axes (compile-time constant).

Definition at line 120 of file tpl_ca_bit_storage.H.

References N.

Referenced by TEST().

◆ extents()

template<std::size_t N>
const extents_type & Aleph::CA::Bit_Cell_Storage< N >::extents ( ) const
inlinenoexcept

Return the full extents array.

Returns
const reference to the array of per-axis extents.

Definition at line 145 of file tpl_ca_bit_storage.H.

References Aleph::CA::Bit_Cell_Storage< N >::ext_.

◆ fill()

template<std::size_t N>
void Aleph::CA::Bit_Cell_Storage< N >::fill ( const bool  value)
inline

Set every cell to value.

Parameters
valuethe boolean value to set.
Note
Does not throw. Sets all bits uniformly.

Definition at line 277 of file tpl_ca_bit_storage.H.

References Aleph::CA::Bit_Cell_Storage< N >::buffer_, Aleph::CA::Bit_Cell_Storage< N >::total_cells_, value, and Aleph::BitArray::write_bit().

Referenced by TEST().

◆ linear_index()

template<std::size_t N>
ca_size_t Aleph::CA::Bit_Cell_Storage< N >::linear_index ( const coord_type &  c) const
inline

Map a multi-index to a linear bit offset (row-major).

Parameters
[in]cmulti-dimensional coordinate; each component must satisfy 0 <= c[d] < size(d).
Returns
flat bit index in [0, total cell count).
Exceptions
std::out_of_rangeif any component is out of range.

Definition at line 156 of file tpl_ca_bit_storage.H.

References ah_out_of_range_error_if, Aleph::blossom_maximum_cardinality_matching(), Aleph::CA::Bit_Cell_Storage< N >::ext_, and N.

Referenced by Aleph::CA::Bit_Cell_Storage< N >::at(), and Aleph::CA::Bit_Cell_Storage< N >::set().

◆ product()

template<std::size_t N>
static ca_size_t Aleph::CA::Bit_Cell_Storage< N >::product ( const extents_type &  e)
inlinestaticprivate

Definition at line 92 of file tpl_ca_bit_storage.H.

References ah_overflow_error_if, and N.

◆ set() [1/4]

template<std::size_t N>
void Aleph::CA::Bit_Cell_Storage< N >::set ( ca_index_t  i,
bool  v 
)
inline

Write 1D cell at index i.

Parameters
ithe column coordinate.
vthe boolean value to write.
Exceptions
std::out_of_rangeif i is out of bounds.

Definition at line 230 of file tpl_ca_bit_storage.H.

References Aleph::CA::Bit_Cell_Storage< N >::set().

◆ set() [2/4]

template<std::size_t N>
void Aleph::CA::Bit_Cell_Storage< N >::set ( ca_index_t  i,
ca_index_t  j,
ca_index_t  k,
const bool  v 
)
inline

Write 3D cell at (i, j, k).

Parameters
ithe depth coordinate.
jthe row coordinate.
kthe column coordinate.
vthe boolean value to write.
Exceptions
std::out_of_rangeif the coordinate is out of bounds.

Definition at line 255 of file tpl_ca_bit_storage.H.

References k, and Aleph::CA::Bit_Cell_Storage< N >::set().

◆ set() [3/4]

template<std::size_t N>
void Aleph::CA::Bit_Cell_Storage< N >::set ( ca_index_t  i,
ca_index_t  j,
const bool  v 
)
inline

Write 2D cell at (i, j).

Parameters
ithe row coordinate.
jthe column coordinate.
vthe boolean value to write.
Exceptions
std::out_of_rangeif the coordinate is out of bounds.

Definition at line 242 of file tpl_ca_bit_storage.H.

References Aleph::CA::Bit_Cell_Storage< N >::set().

◆ set() [4/4]

template<std::size_t N>
void Aleph::CA::Bit_Cell_Storage< N >::set ( const coord_type &  c,
bool  v 
)
inline

Write the cell at coordinate c.

Parameters
[in]cmulti-dimensional coordinate.
[in]vboolean value to store.
Exceptions
std::out_of_rangeif any component of c is out of range.

Definition at line 184 of file tpl_ca_bit_storage.H.

References Aleph::CA::Bit_Cell_Storage< N >::buffer_, Aleph::CA::Bit_Cell_Storage< N >::linear_index(), and Aleph::BitArray::write_bit().

Referenced by Aleph::CA::Bit_Cell_Storage< N >::set(), Aleph::CA::Bit_Cell_Storage< N >::set(), Aleph::CA::Bit_Cell_Storage< N >::set(), TEST(), and TEST().

◆ size() [1/2]

template<std::size_t N>
ca_size_t Aleph::CA::Bit_Cell_Storage< N >::size ( ) const
inlinenoexcept
Returns
total cell count (product of extents).

Definition at line 126 of file tpl_ca_bit_storage.H.

References Aleph::CA::Bit_Cell_Storage< N >::total_cells_.

Referenced by TEST().

◆ size() [2/2]

template<std::size_t N>
ca_size_t Aleph::CA::Bit_Cell_Storage< N >::size ( std::size_t  d) const
inline

Return the extent (number of cells) along axis d.

Parameters
daxis index in [0, N).
Returns
number of cells along axis d.
Exceptions
std::out_of_rangeif d >= N.

Definition at line 136 of file tpl_ca_bit_storage.H.

References ah_out_of_range_error_if, Aleph::CA::Bit_Cell_Storage< N >::ext_, and N.

◆ swap()

template<std::size_t N>
void Aleph::CA::Bit_Cell_Storage< N >::swap ( Bit_Cell_Storage< N > &  other)
inlinenoexcept

Member Data Documentation

◆ buffer_

◆ ext_

◆ rank

template<std::size_t N>
constexpr std::size_t Aleph::CA::Bit_Cell_Storage< N >::rank = N
staticconstexpr

Number of axes known at compile time.

Definition at line 85 of file tpl_ca_bit_storage.H.

◆ total_cells_

template<std::size_t N>
ca_size_t Aleph::CA::Bit_Cell_Storage< N >::total_cells_ = 0
private

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