initial commit
This commit is contained in:
38
EndlessAVG.h
Executable file
38
EndlessAVG.h
Executable file
@@ -0,0 +1,38 @@
|
||||
#ifndef ENDLESSAVG_H
|
||||
#define ENDLESSAVG_H
|
||||
|
||||
template <typename T> class EndlessAVG {
|
||||
|
||||
private:
|
||||
|
||||
/** track the current sum of the vector's values */
|
||||
T curSum;
|
||||
|
||||
/** the number of elements to average */
|
||||
int count;
|
||||
|
||||
public:
|
||||
|
||||
/** ctor */
|
||||
EndlessAVG() : curSum(), count(0) {;}
|
||||
|
||||
/** add a new value */
|
||||
void add(const T val) {
|
||||
curSum += val;
|
||||
++count;
|
||||
}
|
||||
|
||||
/** get the current average */
|
||||
T get() const {
|
||||
return curSum / count;
|
||||
}
|
||||
|
||||
/** get number of entries to average */
|
||||
int getSize() const {
|
||||
return count;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif // ENDLESSAVG_H
|
||||
Reference in New Issue
Block a user