Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #include "stats.h"
00039 #include <string.h>
00040 #include <math.h>
00041 #include <stdlib.h>
00042 #include <stdio.h>
00043
00044 void initStats(Stats * s, const char * name, const char* unit) {
00045 s->min = (int) pow(2.0, 32.0) - 1;
00046 s->max = 0;
00047 s->mean = 0;
00048 s->pos_max = 0;
00049 s->pos_min = 0;
00050 s->sum = 0;
00051 s->bookmark = 0;
00052 s->idx = 0;
00053 sprintf(s->name,"%s",name);
00054 sprintf(s->unit,"%s",unit);
00055 s->v.clear();
00056 s->v2.clear();
00057 }
00058
00059 void initStats(Stats * s, const char * name, const char* unit, const char* child_name) {
00060 sprintf(s->child_name, "%s", child_name);
00061 initStats(s, name, unit);
00062 }
00063
00064
00065 void updateStat(Stats * s, int val, int pos) {
00066 s->idx++;
00067 s->sum += val;
00068 if (val > s->max) {
00069 s->max = val;
00070 s->pos_max = pos;
00071 }
00072 if (val < s->min) {
00073 s->min = val;
00074 s->pos_min = pos;
00075 }
00076 s->v.push_back(val);
00077 }
00078
00079
00080 void addElement(Stats * s, int value, int pos) {
00081 s->sum += value;
00082 s->v.push_back(value);
00083 s->v2.push_back(pos);
00084 s->idx++;
00085 }
00086
00087
00088 void updateValueStats(Stats * s, int value, int index) {
00089 while ((index + 1) > s->v.size()) {
00090 s->v.push_back(0);
00091 s->v2.push_back(0);
00092 }
00093 s->v.at(index) += value;
00094 s->v2.at(index)++;
00095 s->idx++;
00096 }
00097
00098
00099 void updateValueStats2(Stats * s, int value, int index) {
00100 while ((index + 1) > s->v.size()) {
00101 s->v.push_back(0);
00102 s->v2.push_back(0);
00103 }
00104 s->v.at(index) += value;
00105 s->v2.at(index) += value;
00106 s->idx+=value;
00107 }