MayaFlux 0.2.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
MayaFlux::Memory::HistoryBuffer< T > Class Template Reference

History buffer for difference equations and recursive relations. More...

#include <RingBuffer.hpp>

+ Inheritance diagram for MayaFlux::Memory::HistoryBuffer< T >:
+ Collaboration diagram for MayaFlux::Memory::HistoryBuffer< T >:

Public Types

using value_type = T
 
using reference = T &
 
using const_reference = const T &
 

Public Member Functions

 HistoryBuffer (size_t capacity)
 Construct history buffer with specified capacity.
 
void push (const T &value)
 Push new value to front of history.
 
reference operator[] (size_t index)
 Access element by temporal offset.
 
const_reference operator[] (size_t index) const
 
reference newest ()
 Get newest element (same as [0])
 
const_reference newest () const
 
reference oldest ()
 Get oldest element (same as [capacity-1])
 
const_reference oldest () const
 
void overwrite_newest (const T &value)
 Overwrite the newest element without advancing position.
 
std::span< T > linearized_view ()
 Get mutable linearized view of entire history.
 
std::span< const T > linearized_view () const
 Get const linearized view.
 
void update (size_t index, const T &value)
 Update element at specific index.
 
void reset ()
 Reset buffer to initial state (all zeros)
 
void set_initial_conditions (const std::vector< T > &values)
 Set initial conditions.
 
void resize (size_t new_capacity)
 Resize buffer capacity.
 
size_t capacity () const
 Get buffer capacity.
 
size_t size () const
 Get current count (always equals capacity for HistoryBuffer)
 
bool empty () const
 Check if buffer is empty (always false for HistoryBuffer)
 
std::vector< T > save_state () const
 Save current state for later restoration.
 
void restore_state (const std::vector< T > &state)
 Restore previously saved state.
 

Private Attributes

size_t m_capacity
 
std::vector< T > m_data
 
std::vector< T > m_linear_view
 
size_t m_head {}
 
size_t m_count
 

Detailed Description

template<typename T>
class MayaFlux::Memory::HistoryBuffer< T >

History buffer for difference equations and recursive relations.

Specialized ring buffer for maintaining temporal history in mathematical computations. Pre-initialized to full capacity with zeros to match standard mathematical notation where y[n-k] is defined for all k < N from the start (initial conditions = 0).

Key Differences from Generic RingBuffer:

  • Pre-filled to capacity on construction (all zeros)
  • Always returns full-size mutable spans (size = capacity)
  • Direct mutable element access via operator[]
  • Matches mathematical notation: y[0] = newest, y[k] = k steps back
Template Parameters
TElement type
// IIR filter: y[n] = 0.8·y[n-1] - 0.5·y[n-2] + x[n]
HistoryBuffer<double> y_history(2); // Pre-filled with [0.0, 0.0]
for (auto x : input_signal) {
y_history.push(x); // Current input becomes y[0]
double y_n = y_history[0]; // y[n] (just pushed)
double y_n1 = y_history[1]; // y[n-1]
double y_n2 = y_history[2]; // y[n-2]
double output = 0.8*y_n1 - 0.5*y_n2 + y_n;
y_history.overwrite_newest(output); // Replace y[n] with computed output
}
History buffer for difference equations and recursive relations.

Definition at line 344 of file RingBuffer.hpp.


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