Mercurial > hg > beaglert
changeset 140:5edc6d0713ef ClockSync
MovingAverage: added reset() method and edited getLength() to return current length
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Mon, 14 Sep 2015 14:57:54 +0100 |
parents | 4e2dd3eb1d28 |
children | 44d07fa9bd03 |
files | include/stats.hpp |
diffstat | 1 files changed, 6 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/include/stats.hpp Sun Sep 13 21:34:47 2015 +0100 +++ b/include/stats.hpp Mon Sep 14 14:57:54 2015 +0100 @@ -28,8 +28,7 @@ if(array==NULL) printf("Error while allocating array\n"); memset(array, 0, sizeof(TYPE)*length); - pointer=0; - bufferFull=false; + reset(); } public: MovingAverage(){ @@ -42,7 +41,7 @@ dealloc(); } int getLength(){ - return length; + return bufferFull ? length : pointer; } void setLength(int aLength){ dealloc(); @@ -68,6 +67,10 @@ double getAverage(){ return average; } + void reset(){ + pointer=0; + bufferFull=false; + } }; #endif /* STATS_HPP_INCLUDED */