comparison include/stats.hpp @ 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 aac018615930
children
comparison
equal deleted inserted replaced
139:4e2dd3eb1d28 140:5edc6d0713ef
26 array=(TYPE*)malloc(sizeof(TYPE)*length); 26 array=(TYPE*)malloc(sizeof(TYPE)*length);
27 sum=0; 27 sum=0;
28 if(array==NULL) 28 if(array==NULL)
29 printf("Error while allocating array\n"); 29 printf("Error while allocating array\n");
30 memset(array, 0, sizeof(TYPE)*length); 30 memset(array, 0, sizeof(TYPE)*length);
31 pointer=0; 31 reset();
32 bufferFull=false;
33 } 32 }
34 public: 33 public:
35 MovingAverage(){ 34 MovingAverage(){
36 init(0); 35 init(0);
37 } 36 }
40 } 39 }
41 ~MovingAverage(){ 40 ~MovingAverage(){
42 dealloc(); 41 dealloc();
43 } 42 }
44 int getLength(){ 43 int getLength(){
45 return length; 44 return bufferFull ? length : pointer;
46 } 45 }
47 void setLength(int aLength){ 46 void setLength(int aLength){
48 dealloc(); 47 dealloc();
49 init(aLength); 48 init(aLength);
50 } 49 }
66 return average; 65 return average;
67 } 66 }
68 double getAverage(){ 67 double getAverage(){
69 return average; 68 return average;
70 } 69 }
70 void reset(){
71 pointer=0;
72 bufferFull=false;
73 }
71 }; 74 };
72 75
73 #endif /* STATS_HPP_INCLUDED */ 76 #endif /* STATS_HPP_INCLUDED */