mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/sta-peak.git
synced 2025-06-12 19:05:58 +00:00
38 lines
972 B
C++
38 lines
972 B
C++
#ifndef INC_ROLLING_AVG_HPP_
|
|
#define INC_ROLLING_AVG_HPP_
|
|
|
|
namespace sta
|
|
{
|
|
namespace math
|
|
{
|
|
|
|
/// Rolling average class, using a ring buffer
|
|
template <typename T> class RollingAverage
|
|
{
|
|
public:
|
|
using Value = T;
|
|
|
|
/// @brief Determines rolling average for a given size, discarding the oldest value
|
|
/// @param size Size of the rolling average
|
|
RollingAverage(int size);
|
|
~RollingAverage();
|
|
|
|
/// @brief Adds a value to the rolling average
|
|
/// @param value Value to add
|
|
void add(Value value);
|
|
|
|
/// @brief Returns the current rolling average
|
|
/// @return Current rolling average
|
|
Value get();
|
|
|
|
private:
|
|
Value *values_;
|
|
int size_;
|
|
int index_;
|
|
Value sum_;
|
|
};
|
|
} // namespace math
|
|
} // namespace sta
|
|
|
|
#endif /* INC_ROLLING_AVG_HPP_ */
|