From 4a3ce94386da669e82e1fd32fb201e2c9385938e Mon Sep 17 00:00:00 2001 From: Lisa Hsu Date: Thu, 3 Jun 2010 11:06:12 -0700 Subject: Stats: fix dist stat and enable VectorDistStat --- src/base/statistics.hh | 23 ++++++++++++++--------- src/base/stats/text.cc | 2 +- 2 files changed, 15 insertions(+), 10 deletions(-) (limited to 'src/base') diff --git a/src/base/statistics.hh b/src/base/statistics.hh index 06a9d465d..f7625779a 100644 --- a/src/base/statistics.hh +++ b/src/base/statistics.hh @@ -1698,7 +1698,11 @@ class VectorDistBase : public DataWrapVec delete [] reinterpret_cast(storage); } - Proxy operator[](off_type index); + Proxy operator[](off_type index) + { + assert(index >= 0 && index < size()); + return Proxy(this->self(), index); + } size_type size() const @@ -1739,15 +1743,15 @@ template class DistProxy { private: - Stat *stat; + Stat &stat; off_type index; protected: - typename Stat::Storage *data() { return stat->data(index); } - const typename Stat::Storage *data() const { return stat->data(index); } + typename Stat::Storage *data() { return stat.data(index); } + const typename Stat::Storage *data() const { return stat.data(index); } public: - DistProxy(Stat *s, off_type i) + DistProxy(Stat &s, off_type i) : stat(s), index(i) {} @@ -1788,15 +1792,16 @@ class DistProxy */ void reset() { } }; - +/* template inline typename VectorDistBase::Proxy VectorDistBase::operator[](off_type index) { assert (index >= 0 && index < size()); typedef typename VectorDistBase::Proxy Proxy; - return Proxy(this, index); + return Proxy(this->self(), index); } +*/ #if 0 template @@ -2267,7 +2272,7 @@ class Distribution : public DistBase params->min = min; params->max = max; params->bucket_size = bkt; - params->buckets = (size_type)rint((max - min) / bkt + 1.0); + params->buckets = (size_type)rint((max - min + 1.0) / bkt ); this->setParams(params); this->doInit(); return this->self(); @@ -2328,7 +2333,7 @@ class VectorDistribution : public VectorDistBase params->min = min; params->max = max; params->bucket_size = bkt; - params->buckets = (size_type)rint((max - min) / bkt + 1.0); + params->buckets = (size_type)rint((max - min + 1.0) / bkt); this->setParams(params); this->doInit(size); return this->self(); diff --git a/src/base/stats/text.cc b/src/base/stats/text.cc index 10983506f..090ddff7d 100644 --- a/src/base/stats/text.cc +++ b/src/base/stats/text.cc @@ -412,7 +412,7 @@ DistPrint::operator()(ostream &stream) const namestr << base; Counter low = i * bucket_size + min; - Counter high = ::min(low + bucket_size, max); + Counter high = ::min(low + bucket_size - 1.0, max); namestr << low; if (low < high) namestr << "-" << high; -- cgit v1.2.3