carl  24.04
Computer ARithmetic Library
Series.h
Go to the documentation of this file.
1 #pragma once
2 
3 namespace carl::statistics {
4 
5 class Series {
6  std::size_t m_count = 0;
7  std::size_t m_sum = 0;
8  std::size_t m_min = 0;
9  std::size_t m_max = 0;
10 
11 public:
12  void add(std::size_t n) {
13  m_sum += n;
14  m_min = m_count == 0 ? n : std::min(m_min, n);
15  m_max = m_count == 0 ? n : std::max(m_max, n);
16  m_count++;
17  }
18 
19  void collect(std::map<std::string, std::string>& data, const std::string& key) const {
20  data.emplace(key+".count", std::to_string(m_count));
21  data.emplace(key+".sum", std::to_string(m_sum));
22  data.emplace(key+".min", std::to_string(m_min));
23  data.emplace(key+".max", std::to_string(m_max));
24  data.emplace(key+".avg", std::to_string((float)m_sum/(float)m_count));
25  }
26 };
27 
28 }
std::size_t m_min
Definition: Series.h:8
std::size_t m_count
Definition: Series.h:6
std::size_t m_sum
Definition: Series.h:7
std::size_t m_max
Definition: Series.h:9
void collect(std::map< std::string, std::string > &data, const std::string &key) const
Definition: Series.h:19
void add(std::size_t n)
Definition: Series.h:12