Advanced Chunk Processing Library 0.2.0
A comprehensive C++ library for advanced data chunking strategies and processing operations
Loading...
Searching...
No Matches
SlidingWindow< T > Class Template Reference

#include <data_structures.hpp>

Public Member Functions

 SlidingWindow (size_t size)
 
average () const
 
bool empty () const
 
void push (const T &value)
 
size_t size () const
 
sum () const
 
const std::deque< T > & window () const
 

Private Attributes

size_t max_size_
 
sum_ = T()
 
std::deque< T > window_
 

Detailed Description

template<typename T>
class SlidingWindow< T >

Definition at line 138 of file data_structures.hpp.

Constructor & Destructor Documentation

◆ SlidingWindow()

template<typename T >
SlidingWindow< T >::SlidingWindow ( size_t  size)
inlineexplicit

Definition at line 145 of file data_structures.hpp.

145 : max_size_(size) {
146 if (size == 0)
147 throw std::invalid_argument("Window size must be positive");
148 }
size_t size() const

References SlidingWindow< T >::size().

Member Function Documentation

◆ average()

template<typename T >
T SlidingWindow< T >::average ( ) const
inline

Definition at line 160 of file data_structures.hpp.

160 {
161 if (window_.empty())
162 throw std::runtime_error("Window is empty");
163 return sum_ / static_cast<T>(window_.size());
164 }
std::deque< T > window_

References SlidingWindow< T >::sum_, and SlidingWindow< T >::window_.

Referenced by TEST().

◆ empty()

template<typename T >
bool SlidingWindow< T >::empty ( ) const
inline

Definition at line 172 of file data_structures.hpp.

172 {
173 return window_.empty();
174 }

References SlidingWindow< T >::window_.

◆ push()

template<typename T >
void SlidingWindow< T >::push ( const T &  value)
inline

Definition at line 150 of file data_structures.hpp.

150 {
151 window_.push_back(value);
152 sum_ += value;
153
154 if (window_.size() > max_size_) {
155 sum_ -= window_.front();
156 window_.pop_front();
157 }
158 }

References SlidingWindow< T >::max_size_, SlidingWindow< T >::sum_, and SlidingWindow< T >::window_.

Referenced by TEST().

◆ size()

template<typename T >
size_t SlidingWindow< T >::size ( ) const
inline

Definition at line 169 of file data_structures.hpp.

169 {
170 return window_.size();
171 }

References SlidingWindow< T >::window_.

Referenced by SlidingWindow< T >::SlidingWindow().

◆ sum()

template<typename T >
T SlidingWindow< T >::sum ( ) const
inline

Definition at line 175 of file data_structures.hpp.

175 {
176 return sum_;
177 }

References SlidingWindow< T >::sum_.

◆ window()

template<typename T >
const std::deque< T > & SlidingWindow< T >::window ( ) const
inline

Definition at line 166 of file data_structures.hpp.

166 {
167 return window_;
168 }

References SlidingWindow< T >::window_.

Member Data Documentation

◆ max_size_

template<typename T >
size_t SlidingWindow< T >::max_size_
private

Definition at line 141 of file data_structures.hpp.

Referenced by SlidingWindow< T >::push().

◆ sum_

template<typename T >
T SlidingWindow< T >::sum_ = T()
private

◆ window_

template<typename T >
std::deque<T> SlidingWindow< T >::window_
private

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