Commit 388a7628 authored by Mathieu Giraud's avatar Mathieu Giraud
Browse files

core/stats.{h,cpp}: Storing number and length statistics

In the future, we could store histogram data here.
parent 088ac346
#include "stats.h"
Stats::Stats()
{
nb = 0 ;
length = 0 ;
}
void Stats::setLabel(string _label)
{
label = _label ;
}
void Stats::insert(int _length)
{
nb++ ;
length += _length ;
}
float Stats::getAverageLength()
{
return (float) length / nb ;
}
ostream &operator<<(ostream &out, Stats &stats)
{
out << " " << left << setw(20) << stats.label
<< " ->" << right << setw(9) << stats.nb ;
if (stats.nb)
out << " " << setw(5) << fixed << setprecision(1) << stats.getAverageLength() ;
out << endl ;
return out;
}
#ifndef STATS_H
#define STATS_H
#include <string>
#include <iostream>
#include <iomanip>
using namespace std;
class Stats {
public:
string label;
int nb;
int length;
public:
Stats();
void setLabel(string _label);
void insert(int _length);
float getAverageLength();
};
ostream &operator<<(ostream &out, Stats &stats);
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment