OpenLB 1.7
Loading...
Searching...
No Matches
Public Member Functions | List of all members
olb::util::CircularBuffer< T > Class Template Reference

Simple circular buffer to compute average and other quantities over pre-defined temporal windows. More...

#include <benchmarkUtil.h>

+ Collaboration diagram for olb::util::CircularBuffer< T >:

Public Member Functions

 CircularBuffer (int size)
 
void insert (T entry)
 insert a new entry ed eventually erases the oldest one
 
average ()
 average over all the entries
 
T & get (int pos)
 get reference to the last entry for pos=0, the second-to-last for pos=1, and so on
 
int getSize ()
 return size of the buffer
 

Detailed Description

template<typename T>
class olb::util::CircularBuffer< T >

Simple circular buffer to compute average and other quantities over pre-defined temporal windows.

Works with every T supporting += (T or scalar), and /= (scalar) operations, including double and Vector<double, size>.

Definition at line 158 of file benchmarkUtil.h.

Constructor & Destructor Documentation

◆ CircularBuffer()

template<typename T >
olb::util::CircularBuffer< T >::CircularBuffer ( int size)

Definition at line 328 of file benchmarkUtil.hh.

329 : _size(size)
330{}

Member Function Documentation

◆ average()

template<typename T >
T olb::util::CircularBuffer< T >::average ( )

average over all the entries

Definition at line 342 of file benchmarkUtil.hh.

343{
344 T avg = T();
345 for (auto i=_data.begin(); i!=_data.end(); i++) {
346 avg += *i;
347 }
348 avg *= 1. / _data.size();
349 return avg;
350}

◆ get()

template<typename T >
T & olb::util::CircularBuffer< T >::get ( int pos)

get reference to the last entry for pos=0, the second-to-last for pos=1, and so on

Definition at line 353 of file benchmarkUtil.hh.

354{
355 if (pos < 0) {
356 return _data.back();
357 }
358
359 if (pos >= _size) {
360 return _data.front();
361 }
362
363 return _data[_size - 1 - pos];;
364}

◆ getSize()

template<typename T >
int olb::util::CircularBuffer< T >::getSize ( )

return size of the buffer

Definition at line 367 of file benchmarkUtil.hh.

368{
369 return _size;
370}

◆ insert()

template<typename T >
void olb::util::CircularBuffer< T >::insert ( T entry)

insert a new entry ed eventually erases the oldest one

Definition at line 333 of file benchmarkUtil.hh.

334{
335 _data.push_back(entry);
336 if (_data.size() > static_cast<unsigned int>(_size) ) {
337 _data.erase( _data.begin() );
338 }
339}

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