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

Cell state carrying a fixed-depth ring buffer of past values. More...

#include <tpl_ca_continuous_rules.H>

Collaboration diagram for Aleph::CA::History_Cell< State, Depth >:
[legend]

Public Types

using value_type = State
 Base value type stored in the ring buffer.
 

Public Member Functions

 History_Cell ()=default
 Construct a zero/default history.
 
 History_Cell (const State &value)
 Construct a history with every slot initialized to value.
 
 History_Cell (const std::array< State, Depth > &values, const std::size_t head=0)
 Construct a history from raw ring contents.
 
State current () const
 Return the current value.
 
State previous (const std::size_t age) const
 Return a previous value by age.
 
void push (const State &value)
 Push a new current value into the ring.
 
std::size_t head () const noexcept
 Return the current ring head index.
 
const std::array< State, Depth > & values () const noexcept
 Return the raw ring storage.
 
bool operator== (const History_Cell &rhs) const
 Compare two history cells exactly.
 

Static Public Attributes

static constexpr std::size_t depth_v = Depth
 Number of retained states.
 

Private Attributes

std::array< State, Depth > values_ {}
 
std::size_t head_ = 0
 

Detailed Description

template<typename State, std::size_t Depth>
class Aleph::CA::History_Cell< State, Depth >

Cell state carrying a fixed-depth ring buffer of past values.

current() returns the value at the active ring head. previous(1) returns the value that was current before the last push(), and so on up to previous(Depth - 1).

Template Parameters
Statevalue stored in each history slot.
Depthnumber of slots retained per cell; must be positive.

Definition at line 635 of file tpl_ca_continuous_rules.H.

Member Typedef Documentation

◆ value_type

template<typename State , std::size_t Depth>
using Aleph::CA::History_Cell< State, Depth >::value_type = State

Base value type stored in the ring buffer.

Definition at line 641 of file tpl_ca_continuous_rules.H.

Constructor & Destructor Documentation

◆ History_Cell() [1/3]

template<typename State , std::size_t Depth>
Aleph::CA::History_Cell< State, Depth >::History_Cell ( )
default

Construct a zero/default history.

Exceptions
Thisfunction does not throw if State construction does not throw.

◆ History_Cell() [2/3]

template<typename State , std::size_t Depth>
Aleph::CA::History_Cell< State, Depth >::History_Cell ( const State &  value)
inlineexplicit

Construct a history with every slot initialized to value.

Parameters
[in]valuevalue copied into every slot.
Exceptions
Anyexception thrown by State copy assignment.

Definition at line 662 of file tpl_ca_continuous_rules.H.

References value, and Aleph::CA::History_Cell< State, Depth >::values_.

◆ History_Cell() [3/3]

template<typename State , std::size_t Depth>
Aleph::CA::History_Cell< State, Depth >::History_Cell ( const std::array< State, Depth > &  values,
const std::size_t  head = 0 
)
inline

Construct a history from raw ring contents.

Parameters
[in]valuesring storage.
[in]headindex of the current value.
Exceptions
std::out_of_rangeif head >= Depth.

Definition at line 673 of file tpl_ca_continuous_rules.H.

References ah_out_of_range_error_if, Aleph::blossom_maximum_cardinality_matching(), and Aleph::CA::History_Cell< State, Depth >::head_.

Member Function Documentation

◆ current()

template<typename State , std::size_t Depth>
State Aleph::CA::History_Cell< State, Depth >::current ( ) const
inline

Return the current value.

Returns
value at the ring head.
Exceptions
Thisfunction does not throw if State copy does not throw.

Definition at line 685 of file tpl_ca_continuous_rules.H.

References Aleph::CA::History_Cell< State, Depth >::head_, and Aleph::CA::History_Cell< State, Depth >::values_.

Referenced by Aleph::CA::History_Rule< Depth, F >::operator()().

◆ head()

template<typename State , std::size_t Depth>
std::size_t Aleph::CA::History_Cell< State, Depth >::head ( ) const
inlinenoexcept

Return the current ring head index.

Returns
index in [0, Depth).
Exceptions
Thisfunction does not throw.

Definition at line 723 of file tpl_ca_continuous_rules.H.

References Aleph::CA::History_Cell< State, Depth >::head_.

◆ operator==()

template<typename State , std::size_t Depth>
bool Aleph::CA::History_Cell< State, Depth >::operator== ( const History_Cell< State, Depth > &  rhs) const
inline

Compare two history cells exactly.

Parameters
[in]rhscell to compare with.
Returns
true when head and all slots match.
Exceptions
Thisfunction does not throw if State comparison does not throw.

Definition at line 745 of file tpl_ca_continuous_rules.H.

References Aleph::and, Aleph::CA::History_Cell< State, Depth >::head_, and Aleph::CA::History_Cell< State, Depth >::values_.

◆ previous()

template<typename State , std::size_t Depth>
State Aleph::CA::History_Cell< State, Depth >::previous ( const std::size_t  age) const
inline

Return a previous value by age.

age == 0 is the current value. age == 1 is the value before the most recent push().

Parameters
[in]ageage in [0, Depth).
Returns
selected historical value.
Exceptions
std::out_of_rangeif age >= Depth.

Definition at line 699 of file tpl_ca_continuous_rules.H.

References ah_out_of_range_error_if, Aleph::blossom_maximum_cardinality_matching(), Aleph::CA::History_Cell< State, Depth >::head_, and Aleph::CA::History_Cell< State, Depth >::values_.

Referenced by Aleph::CA::History_Rule< Depth, F >::operator()().

◆ push()

template<typename State , std::size_t Depth>
void Aleph::CA::History_Cell< State, Depth >::push ( const State &  value)
inline

Push a new current value into the ring.

Parameters
[in]valuevalue that becomes current().
Exceptions
Anyexception thrown by State assignment.

Definition at line 712 of file tpl_ca_continuous_rules.H.

References Aleph::blossom_maximum_cardinality_matching(), Aleph::CA::History_Cell< State, Depth >::head_, value, and Aleph::CA::History_Cell< State, Depth >::values_.

Referenced by Aleph::CA::History_Rule< Depth, F >::operator()().

◆ values()

template<typename State , std::size_t Depth>
const std::array< State, Depth > & Aleph::CA::History_Cell< State, Depth >::values ( ) const
inlinenoexcept

Return the raw ring storage.

Returns
const reference to the stored values.
Exceptions
Thisfunction does not throw.

Definition at line 733 of file tpl_ca_continuous_rules.H.

References Aleph::CA::History_Cell< State, Depth >::values_.

Member Data Documentation

◆ depth_v

template<typename State , std::size_t Depth>
constexpr std::size_t Aleph::CA::History_Cell< State, Depth >::depth_v = Depth
staticconstexpr

Number of retained states.

Definition at line 643 of file tpl_ca_continuous_rules.H.

◆ head_

◆ values_


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