Electroneum
epee::math_helper::average< val, default_base > Class Template Reference

#include <math_helper.h>

Public Types

typedef val value_type
 

Public Member Functions

 average ()
 
bool set_base ()
 
void push (const value_type &vl)
 
double update (const value_type &vl)
 
double get_avg ()
 
value_type get_last_val ()
 

Detailed Description

template<typename val, int default_base>
class epee::math_helper::average< val, default_base >

Definition at line 48 of file math_helper.h.

Member Typedef Documentation

◆ value_type

template<typename val, int default_base>
typedef val epee::math_helper::average< val, default_base >::value_type

Definition at line 69 of file math_helper.h.

Constructor & Destructor Documentation

◆ average()

template<typename val, int default_base>
epee::math_helper::average< val, default_base >::average ( )
inline

Definition at line 52 of file math_helper.h.

53  {
54  m_base = default_base;
55  m_last_avg_val = 0;
56  }

Member Function Documentation

◆ get_avg()

template<typename val, int default_base>
double epee::math_helper::average< val, default_base >::get_avg ( )
inline

Definition at line 92 of file math_helper.h.

93  {
94  CRITICAL_REGION_LOCAL(m_lock);
95 
96  value_type vl = std::accumulate(m_list.begin(), m_list.end(), value_type(0));
97  if(m_list.size())
98  return m_last_avg_val = (double)(vl/m_list.size());
99 
100  return m_last_avg_val = (double)vl;
101  }
#define CRITICAL_REGION_LOCAL(x)
Definition: syncobj.h:228
Here is the caller graph for this function:

◆ get_last_val()

template<typename val, int default_base>
value_type epee::math_helper::average< val, default_base >::get_last_val ( )
inline

Definition at line 103 of file math_helper.h.

104  {
105  CRITICAL_REGION_LOCAL(m_lock);
106  if(m_list.size())
107  return m_list.back();
108 
109  return 0;
110  }
#define CRITICAL_REGION_LOCAL(x)
Definition: syncobj.h:228

◆ push()

template<typename val, int default_base>
void epee::math_helper::average< val, default_base >::push ( const value_type vl)
inline

Definition at line 71 of file math_helper.h.

72  {
73  CRITICAL_REGION_LOCAL(m_lock);
74 
75 //#ifndef DEBUG_STUB
76  m_list.push_back(vl);
77  if(m_list.size() > m_base )
78  m_list.pop_front();
79 //#endif
80  }
#define CRITICAL_REGION_LOCAL(x)
Definition: syncobj.h:228
Here is the caller graph for this function:

◆ set_base()

template<typename val, int default_base>
bool epee::math_helper::average< val, default_base >::set_base ( )
inline

Definition at line 58 of file math_helper.h.

59  {
60  CRITICAL_REGION_LOCAL(m_lock);
61 
62  m_base = default_base;
63  if(m_list.size() > m_base)
64  m_list.resize(m_base);
65 
66  return true;
67  }
#define CRITICAL_REGION_LOCAL(x)
Definition: syncobj.h:228

◆ update()

template<typename val, int default_base>
double epee::math_helper::average< val, default_base >::update ( const value_type vl)
inline

Definition at line 82 of file math_helper.h.

83  {
84  CRITICAL_REGION_LOCAL(m_lock);
85 //#ifndef DEBUG_STUB
86  push(vl);
87 //#endif
88 
89  return get_avg();
90  }
void push(const value_type &vl)
Definition: math_helper.h:71
#define CRITICAL_REGION_LOCAL(x)
Definition: syncobj.h:228

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