stats: use properly signed types for looping and comparison

This commit is contained in:
Nathan Binkert 2008-10-09 04:58:23 -07:00
parent a52dce6d62
commit 7cc2a88038
6 changed files with 170 additions and 166 deletions

View file

@ -117,8 +117,8 @@ StatData::less(StatData *stat1, StatData *stat2)
tokenize(v1, name1, '.'); tokenize(v1, name1, '.');
tokenize(v2, name2, '.'); tokenize(v2, name2, '.');
int last = min(v1.size(), v2.size()) - 1; size_type last = min(v1.size(), v2.size()) - 1;
for (int i = 0; i < last; ++i) for (off_type i = 0; i < last; ++i)
if (v1[i] != v2[i]) if (v1[i] != v2[i])
return v1[i] < v2[i]; return v1[i] < v2[i];
@ -164,7 +164,7 @@ FormulaBase::total() const
return root ? root->total() : 0.0; return root ? root->total() : 0.0;
} }
size_t size_type
FormulaBase::size() const FormulaBase::size() const
{ {
if (!root) if (!root)
@ -183,7 +183,7 @@ FormulaBase::zero() const
{ {
VResult vec; VResult vec;
result(vec); result(vec);
for (int i = 0; i < vec.size(); ++i) for (off_t i = 0; i < vec.size(); ++i)
if (vec[i] != 0.0) if (vec[i] != 0.0)
return false; return false;
return true; return true;
@ -244,7 +244,7 @@ check()
panic("stat check failed for %s\n", data->name); panic("stat check failed for %s\n", data->name);
} }
int j = 0; off_t j = 0;
for (i = Database::stats().begin(); i != end; ++i) { for (i = Database::stats().begin(); i != end; ++i) {
StatData *data = *i; StatData *data = *i;
if (!(data->flags & print)) if (!(data->flags & print))

View file

@ -173,7 +173,7 @@ struct VectorData : public StatData
mutable std::vector<std::string> subnames; mutable std::vector<std::string> subnames;
mutable std::vector<std::string> subdescs; mutable std::vector<std::string> subdescs;
virtual size_t size() const = 0; virtual size_type size() const = 0;
virtual const VCounter &value() const = 0; virtual const VCounter &value() const = 0;
virtual const VResult &result() const = 0; virtual const VResult &result() const = 0;
virtual Result total() const = 0; virtual Result total() const = 0;
@ -182,7 +182,7 @@ struct VectorData : public StatData
update() update()
{ {
if (!subnames.empty()) { if (!subnames.empty()) {
int s = size(); size_type s = size();
if (subnames.size() < s) if (subnames.size() < s)
subnames.resize(s); subnames.resize(s);
@ -207,7 +207,7 @@ class VectorStatData : public VectorData
virtual bool zero() const { return s.zero(); } virtual bool zero() const { return s.zero(); }
virtual void reset() { s.reset(); } virtual void reset() { s.reset(); }
virtual size_t size() const { return s.size(); } virtual size_type size() const { return s.size(); }
virtual VCounter & virtual VCounter &
value() const value() const
@ -248,7 +248,7 @@ struct DistDataData
Counter min; Counter min;
Counter max; Counter max;
Counter bucket_size; Counter bucket_size;
int size; size_type size;
bool fancy; bool fancy;
}; };
@ -290,12 +290,12 @@ struct VectorDistData : public StatData
/** Local storage for the entry values, used for printing. */ /** Local storage for the entry values, used for printing. */
mutable VResult rvec; mutable VResult rvec;
virtual size_t size() const = 0; virtual size_type size() const = 0;
void void
update() update()
{ {
int s = size(); size_type s = size();
if (subnames.size() < s) if (subnames.size() < s)
subnames.resize(s); subnames.resize(s);
@ -315,7 +315,7 @@ class VectorDistStatData : public VectorDistData
virtual bool check() const { return s.check(); } virtual bool check() const { return s.check(); }
virtual void reset() { s.reset(); } virtual void reset() { s.reset(); }
virtual size_t size() const { return s.size(); } virtual size_type size() const { return s.size(); }
virtual bool zero() const { return s.zero(); } virtual bool zero() const { return s.zero(); }
virtual void virtual void
@ -336,8 +336,8 @@ struct Vector2dData : public StatData
/** Local storage for the entry values, used for printing. */ /** Local storage for the entry values, used for printing. */
mutable VCounter cvec; mutable VCounter cvec;
mutable int x; mutable size_type x;
mutable int y; mutable size_type y;
void void
update() update()
@ -506,7 +506,7 @@ class WrapVec : public Wrap<Parent, Child, Data>
* @return A reference to this stat. * @return A reference to this stat.
*/ */
Parent & Parent &
subname(int index, const std::string &name) subname(off_type index, const std::string &name)
{ {
std::vector<std::string> &subn = this->statData()->subnames; std::vector<std::string> &subn = this->statData()->subnames;
if (subn.size() <= index) if (subn.size() <= index)
@ -523,7 +523,7 @@ class WrapVec : public Wrap<Parent, Child, Data>
* @return A reference to this stat. * @return A reference to this stat.
*/ */
Parent & Parent &
subdesc(int index, const std::string &desc) subdesc(off_type index, const std::string &desc)
{ {
std::vector<std::string> &subd = this->statData()->subdescs; std::vector<std::string> &subd = this->statData()->subdescs;
if (subd.size() <= index) if (subd.size() <= index)
@ -548,13 +548,13 @@ class WrapVec2d : public WrapVec<Parent, Child, Data>
{ {
Data<Child> *data = this->statData(); Data<Child> *data = this->statData();
data->y_subnames.resize(this->y); data->y_subnames.resize(this->y);
for (int i = 0; i < this->y; ++i) for (off_type i = 0; i < this->y; ++i)
data->y_subnames[i] = names[i]; data->y_subnames[i] = names[i];
return this->self(); return this->self();
} }
Parent & Parent &
ysubname(int index, const std::string subname) ysubname(off_type index, const std::string subname)
{ {
Data<Child> *data = this->statData(); Data<Child> *data = this->statData();
assert(index < this->y); assert(index < this->y);
@ -832,7 +832,7 @@ class ScalarBase : public DataAccess
* Return the number of elements, always 1 for a scalar. * Return the number of elements, always 1 for a scalar.
* @return 1. * @return 1.
*/ */
size_t size() const { return 1; } size_type size() const { return 1; }
bool check() const { return true; } bool check() const { return true; }
@ -856,7 +856,7 @@ class ProxyData : public ScalarData
public: public:
virtual void visit(Visit &visitor) { visitor.visit(*this); } virtual void visit(Visit &visitor) { visitor.visit(*this); }
virtual std::string str() const { return to_string(value()); } virtual std::string str() const { return to_string(value()); }
virtual size_t size() const { return 1; } virtual size_type size() const { return 1; }
virtual bool zero() const { return value() == 0; } virtual bool zero() const { return value() == 0; }
virtual bool check() const { return true; } virtual bool check() const { return true; }
virtual void reset() { } virtual void reset() { }
@ -916,7 +916,7 @@ class ValueBase : public DataAccess
Counter value() { return proxy->value(); } Counter value() { return proxy->value(); }
Result result() const { return proxy->result(); } Result result() const { return proxy->result(); }
Result total() const { return proxy->total(); }; Result total() const { return proxy->total(); };
size_t size() const { return proxy->size(); } size_type size() const { return proxy->size(); }
std::string str() const { return proxy->str(); } std::string str() const { return proxy->str(); }
bool zero() const { return proxy->zero(); } bool zero() const { return proxy->zero(); }
@ -942,7 +942,7 @@ class ScalarProxy
Stat *stat; Stat *stat;
/** The index to access in the parent VectorBase. */ /** The index to access in the parent VectorBase. */
int index; off_type index;
public: public:
/** /**
@ -963,7 +963,7 @@ class ScalarProxy
* @param p The params to use. * @param p The params to use.
* @param i The index to access. * @param i The index to access.
*/ */
ScalarProxy(Stat *s, int i) ScalarProxy(Stat *s, off_type i)
: stat(s), index(i) : stat(s), index(i)
{ {
assert(stat); assert(stat);
@ -1047,7 +1047,7 @@ class ScalarProxy
* Return the number of elements, always 1 for a scalar. * Return the number of elements, always 1 for a scalar.
* @return 1. * @return 1.
*/ */
size_t size() const { return 1; } size_type size() const { return 1; }
/** /**
* This stat has no state. Nothing to reset * This stat has no state. Nothing to reset
@ -1083,7 +1083,7 @@ class VectorBase : public DataAccess
protected: protected:
/** The storage of this stat. */ /** The storage of this stat. */
Storage *storage; Storage *storage;
size_t _size; size_type _size;
/** The parameters for this stat. */ /** The parameters for this stat. */
Params params; Params params;
@ -1094,17 +1094,17 @@ class VectorBase : public DataAccess
* @param index The vector index to access. * @param index The vector index to access.
* @return The storage object at the given index. * @return The storage object at the given index.
*/ */
Storage *data(int index) { return &storage[index]; } Storage *data(off_type index) { return &storage[index]; }
/** /**
* Retrieve a const pointer to the storage. * Retrieve a const pointer to the storage.
* @param index The vector index to access. * @param index The vector index to access.
* @return A const pointer to the storage object at the given index. * @return A const pointer to the storage object at the given index.
*/ */
const Storage *data(int index) const { return &storage[index]; } const Storage *data(off_type index) const { return &storage[index]; }
void void
doInit(int s) doInit(size_type s)
{ {
assert(s > 0 && "size must be positive!"); assert(s > 0 && "size must be positive!");
assert(!storage && "already initialized"); assert(!storage && "already initialized");
@ -1113,7 +1113,7 @@ class VectorBase : public DataAccess
char *ptr = new char[_size * sizeof(Storage)]; char *ptr = new char[_size * sizeof(Storage)];
storage = reinterpret_cast<Storage *>(ptr); storage = reinterpret_cast<Storage *>(ptr);
for (int i = 0; i < _size; ++i) for (off_type i = 0; i < _size; ++i)
new (&storage[i]) Storage(params); new (&storage[i]) Storage(params);
setInit(); setInit();
@ -1124,7 +1124,7 @@ class VectorBase : public DataAccess
value(VCounter &vec) const value(VCounter &vec) const
{ {
vec.resize(size()); vec.resize(size());
for (int i = 0; i < size(); ++i) for (off_type i = 0; i < size(); ++i)
vec[i] = data(i)->value(params); vec[i] = data(i)->value(params);
} }
@ -1136,7 +1136,7 @@ class VectorBase : public DataAccess
result(VResult &vec) const result(VResult &vec) const
{ {
vec.resize(size()); vec.resize(size());
for (int i = 0; i < size(); ++i) for (off_type i = 0; i < size(); ++i)
vec[i] = data(i)->result(params); vec[i] = data(i)->result(params);
} }
@ -1148,7 +1148,7 @@ class VectorBase : public DataAccess
total() const total() const
{ {
Result total = 0.0; Result total = 0.0;
for (int i = 0; i < size(); ++i) for (off_type i = 0; i < size(); ++i)
total += data(i)->result(params); total += data(i)->result(params);
return total; return total;
} }
@ -1156,12 +1156,12 @@ class VectorBase : public DataAccess
/** /**
* @return the number of elements in this vector. * @return the number of elements in this vector.
*/ */
size_t size() const { return _size; } size_type size() const { return _size; }
bool bool
zero() const zero() const
{ {
for (int i = 0; i < size(); ++i) for (off_type i = 0; i < size(); ++i)
if (data(i)->zero()) if (data(i)->zero())
return false; return false;
return true; return true;
@ -1176,7 +1176,7 @@ class VectorBase : public DataAccess
void void
reset() reset()
{ {
for (int i = 0; i < size(); ++i) for (off_type i = 0; i < size(); ++i)
data(i)->reset(); data(i)->reset();
} }
@ -1190,7 +1190,7 @@ class VectorBase : public DataAccess
if (!storage) if (!storage)
return; return;
for (int i = 0; i < _size; ++i) for (off_type i = 0; i < _size; ++i)
data(i)->~Storage(); data(i)->~Storage();
delete [] reinterpret_cast<char *>(storage); delete [] reinterpret_cast<char *>(storage);
} }
@ -1201,7 +1201,7 @@ class VectorBase : public DataAccess
* @return A reference of the stat. * @return A reference of the stat.
*/ */
Proxy Proxy
operator[](int index) operator[](off_type index)
{ {
assert (index >= 0 && index < size()); assert (index >= 0 && index < size());
return Proxy(this, index); return Proxy(this, index);
@ -1215,21 +1215,21 @@ class VectorProxy
{ {
private: private:
Stat *stat; Stat *stat;
int offset; off_type offset;
int len; size_type len;
private: private:
mutable VResult vec; mutable VResult vec;
typename Stat::Storage * typename Stat::Storage *
data(int index) data(off_type index)
{ {
assert(index < len); assert(index < len);
return stat->data(offset + index); return stat->data(offset + index);
} }
const typename Stat::Storage * const typename Stat::Storage *
data(int index) const data(off_type index) const
{ {
assert(index < len); assert(index < len);
return const_cast<Stat *>(stat)->data(offset + index); return const_cast<Stat *>(stat)->data(offset + index);
@ -1241,7 +1241,7 @@ class VectorProxy
{ {
vec.resize(size()); vec.resize(size());
for (int i = 0; i < size(); ++i) for (off_type i = 0; i < size(); ++i)
vec[i] = data(i)->result(stat->params); vec[i] = data(i)->result(stat->params);
return vec; return vec;
@ -1251,13 +1251,13 @@ class VectorProxy
total() const total() const
{ {
Result total = 0; Result total = 0;
for (int i = 0; i < size(); ++i) for (off_type i = 0; i < size(); ++i)
total += data(i)->result(stat->params); total += data(i)->result(stat->params);
return total; return total;
} }
public: public:
VectorProxy(Stat *s, int o, int l) VectorProxy(Stat *s, off_type o, size_type l)
: stat(s), offset(o), len(l) : stat(s), offset(o), len(l)
{ {
} }
@ -1277,13 +1277,13 @@ class VectorProxy
} }
ScalarProxy<Stat> ScalarProxy<Stat>
operator[](int index) operator[](off_type index)
{ {
assert (index >= 0 && index < size()); assert (index >= 0 && index < size());
return ScalarProxy<Stat>(stat, offset + index); return ScalarProxy<Stat>(stat, offset + index);
} }
size_t size() const { return len; } size_type size() const { return len; }
/** /**
* This stat has no state. Nothing to reset. * This stat has no state. Nothing to reset.
@ -1302,18 +1302,18 @@ class Vector2dBase : public DataAccess
friend class VectorProxy<Vector2dBase<Storage> >; friend class VectorProxy<Vector2dBase<Storage> >;
protected: protected:
size_t x; size_type x;
size_t y; size_type y;
size_t _size; size_type _size;
Storage *storage; Storage *storage;
Params params; Params params;
protected: protected:
Storage *data(int index) { return &storage[index]; } Storage *data(off_type index) { return &storage[index]; }
const Storage *data(int index) const { return &storage[index]; } const Storage *data(off_type index) const { return &storage[index]; }
void void
doInit(int _x, int _y) doInit(size_type _x, size_type _y)
{ {
assert(_x > 0 && _y > 0 && "sizes must be positive!"); assert(_x > 0 && _y > 0 && "sizes must be positive!");
assert(!storage && "already initialized"); assert(!storage && "already initialized");
@ -1329,7 +1329,7 @@ class Vector2dBase : public DataAccess
char *ptr = new char[_size * sizeof(Storage)]; char *ptr = new char[_size * sizeof(Storage)];
storage = reinterpret_cast<Storage *>(ptr); storage = reinterpret_cast<Storage *>(ptr);
for (int i = 0; i < _size; ++i) for (off_type i = 0; i < _size; ++i)
new (&storage[i]) Storage(params); new (&storage[i]) Storage(params);
setInit(); setInit();
@ -1345,7 +1345,7 @@ class Vector2dBase : public DataAccess
if (!storage) if (!storage)
return; return;
for (int i = 0; i < _size; ++i) for (off_type i = 0; i < _size; ++i)
data(i)->~Storage(); data(i)->~Storage();
delete [] reinterpret_cast<char *>(storage); delete [] reinterpret_cast<char *>(storage);
} }
@ -1353,24 +1353,24 @@ class Vector2dBase : public DataAccess
void void
update(Vector2dData *newdata) update(Vector2dData *newdata)
{ {
int size = this->size(); size_type size = this->size();
newdata->cvec.resize(size); newdata->cvec.resize(size);
for (int i = 0; i < size; ++i) for (off_type i = 0; i < size; ++i)
newdata->cvec[i] = data(i)->value(params); newdata->cvec[i] = data(i)->value(params);
} }
std::string ysubname(int i) const { return (*this->y_subnames)[i]; } std::string ysubname(off_type i) const { return (*this->y_subnames)[i]; }
Proxy Proxy
operator[](int index) operator[](off_type index)
{ {
int offset = index * y; off_type offset = index * y;
assert (index >= 0 && offset + index < size()); assert (index >= 0 && offset + index < size());
return Proxy(this, offset, y); return Proxy(this, offset, y);
} }
size_t size_type
size() const size() const
{ {
return _size; return _size;
@ -1381,7 +1381,7 @@ class Vector2dBase : public DataAccess
{ {
return data(0)->zero(); return data(0)->zero();
#if 0 #if 0
for (int i = 0; i < size(); ++i) for (off_type i = 0; i < size(); ++i)
if (!data(i)->zero()) if (!data(i)->zero())
return false; return false;
return true; return true;
@ -1394,7 +1394,7 @@ class Vector2dBase : public DataAccess
void void
reset() reset()
{ {
for (int i = 0; i < size(); ++i) for (off_type i = 0; i < size(); ++i)
data(i)->reset(); data(i)->reset();
} }
@ -1427,7 +1427,7 @@ struct DistStor
/** The number of entries in each bucket. */ /** The number of entries in each bucket. */
Counter bucket_size; Counter bucket_size;
/** The number of buckets. Equal to (max-min)/bucket_size. */ /** The number of buckets. Equal to (max-min)/bucket_size. */
int size; size_type size;
}; };
enum { fancy = false }; enum { fancy = false };
@ -1470,7 +1470,8 @@ struct DistStor
else if (val > params.max) else if (val > params.max)
overflow += number; overflow += number;
else { else {
size_t index = std::floor((val - params.min) / params.bucket_size); size_type index =
(size_type)std::floor((val - params.min) / params.bucket_size);
assert(index < size(params)); assert(index < size(params));
cvec[index] += number; cvec[index] += number;
} }
@ -1492,7 +1493,7 @@ struct DistStor
* @return the number of buckets. * @return the number of buckets.
* @todo Is it faster to return the size from the parameters? * @todo Is it faster to return the size from the parameters?
*/ */
size_t size(const Params &) const { return cvec.size(); } size_type size(const Params &) const { return cvec.size(); }
/** /**
* Returns true if any calls to sample have been made. * Returns true if any calls to sample have been made.
@ -1518,7 +1519,7 @@ struct DistStor
data->underflow = underflow; data->underflow = underflow;
data->overflow = overflow; data->overflow = overflow;
data->cvec.resize(params.size); data->cvec.resize(params.size);
for (int i = 0; i < params.size; ++i) for (off_type i = 0; i < params.size; ++i)
data->cvec[i] = cvec[i]; data->cvec[i] = cvec[i];
data->sum = sum; data->sum = sum;
@ -1537,8 +1538,8 @@ struct DistStor
underflow = 0; underflow = 0;
overflow = 0; overflow = 0;
int size = cvec.size(); size_type size = cvec.size();
for (int i = 0; i < size; ++i) for (off_type i = 0; i < size; ++i)
cvec[i] = Counter(); cvec[i] = Counter();
sum = Counter(); sum = Counter();
@ -1605,7 +1606,7 @@ struct FancyStor
* Return the number of entries in this stat, 1 * Return the number of entries in this stat, 1
* @return 1. * @return 1.
*/ */
size_t size(const Params &) const { return 1; } size_type size(const Params &) const { return 1; }
/** /**
* Return true if no samples have been added. * Return true if no samples have been added.
@ -1675,7 +1676,7 @@ struct AvgFancy
* Return the number of entries, in this case 1. * Return the number of entries, in this case 1.
* @return 1. * @return 1.
*/ */
size_t size(const Params &params) const { return 1; } size_type size(const Params &params) const { return 1; }
/** /**
* Return true if no samples have been added. * Return true if no samples have been added.
@ -1757,7 +1758,7 @@ class DistBase : public DataAccess
* Return the number of entries in this stat. * Return the number of entries in this stat.
* @return The number of entries. * @return The number of entries.
*/ */
size_t size() const { return data()->size(params); } size_type size() const { return data()->size(params); }
/** /**
* Return true if no samples have been added. * Return true if no samples have been added.
* @return True if there haven't been any samples. * @return True if there haven't been any samples.
@ -1801,24 +1802,24 @@ class VectorDistBase : public DataAccess
protected: protected:
Storage *storage; Storage *storage;
size_t _size; size_type _size;
Params params; Params params;
protected: protected:
Storage * Storage *
data(int index) data(off_type index)
{ {
return &storage[index]; return &storage[index];
} }
const Storage * const Storage *
data(int index) const data(off_type index) const
{ {
return &storage[index]; return &storage[index];
} }
void void
doInit(int s) doInit(size_type s)
{ {
assert(s > 0 && "size must be positive!"); assert(s > 0 && "size must be positive!");
assert(!storage && "already initialized"); assert(!storage && "already initialized");
@ -1827,7 +1828,7 @@ class VectorDistBase : public DataAccess
char *ptr = new char[_size * sizeof(Storage)]; char *ptr = new char[_size * sizeof(Storage)];
storage = reinterpret_cast<Storage *>(ptr); storage = reinterpret_cast<Storage *>(ptr);
for (int i = 0; i < _size; ++i) for (off_type i = 0; i < _size; ++i)
new (&storage[i]) Storage(params); new (&storage[i]) Storage(params);
setInit(); setInit();
@ -1843,14 +1844,14 @@ class VectorDistBase : public DataAccess
if (!storage) if (!storage)
return ; return ;
for (int i = 0; i < _size; ++i) for (off_type i = 0; i < _size; ++i)
data(i)->~Storage(); data(i)->~Storage();
delete [] reinterpret_cast<char *>(storage); delete [] reinterpret_cast<char *>(storage);
} }
Proxy operator[](int index); Proxy operator[](off_type index);
size_t size_type
size() const size() const
{ {
return _size; return _size;
@ -1861,7 +1862,7 @@ class VectorDistBase : public DataAccess
{ {
return false; return false;
#if 0 #if 0
for (int i = 0; i < size(); ++i) for (off_type i = 0; i < size(); ++i)
if (!data(i)->zero(params)) if (!data(i)->zero(params))
return false; return false;
return true; return true;
@ -1874,7 +1875,7 @@ class VectorDistBase : public DataAccess
void void
reset() reset()
{ {
for (int i = 0; i < size(); ++i) for (off_type i = 0; i < size(); ++i)
data(i)->reset(); data(i)->reset();
} }
@ -1887,9 +1888,9 @@ class VectorDistBase : public DataAccess
void void
update(VectorDistData *base) update(VectorDistData *base)
{ {
int size = this->size(); size_type size = this->size();
base->data.resize(size); base->data.resize(size);
for (int i = 0; i < size; ++i) { for (off_type i = 0; i < size; ++i) {
base->data[i].fancy = Storage::fancy; base->data[i].fancy = Storage::fancy;
data(i)->update(&(base->data[i]), params); data(i)->update(&(base->data[i]), params);
} }
@ -1901,14 +1902,14 @@ class DistProxy
{ {
private: private:
Stat *stat; Stat *stat;
int index; off_type index;
protected: protected:
typename Stat::Storage *data() { return stat->data(index); } typename Stat::Storage *data() { return stat->data(index); }
const typename Stat::Storage *data() const { return stat->data(index); } const typename Stat::Storage *data() const { return stat->data(index); }
public: public:
DistProxy(Stat *s, int i) DistProxy(Stat *s, off_type i)
: stat(s), index(i) : stat(s), index(i)
{} {}
@ -1932,7 +1933,7 @@ class DistProxy
data()->sample(v, n, stat->params); data()->sample(v, n, stat->params);
} }
size_t size_type
size() const size() const
{ {
return 1; return 1;
@ -1952,7 +1953,7 @@ class DistProxy
template <class Storage> template <class Storage>
inline typename VectorDistBase<Storage>::Proxy inline typename VectorDistBase<Storage>::Proxy
VectorDistBase<Storage>::operator[](int index) VectorDistBase<Storage>::operator[](off_type index)
{ {
assert (index >= 0 && index < size()); assert (index >= 0 && index < size());
return typename VectorDistBase<Storage>::Proxy(this, index); return typename VectorDistBase<Storage>::Proxy(this, index);
@ -1961,10 +1962,10 @@ VectorDistBase<Storage>::operator[](int index)
#if 0 #if 0
template <class Storage> template <class Storage>
Result Result
VectorDistBase<Storage>::total(int index) const VectorDistBase<Storage>::total(off_type index) const
{ {
int total = 0; Result total = 0;
for (int i = 0; i < x_size(); ++i) for (off_type i = 0; i < x_size(); ++i)
total += data(i)->result(stat->params); total += data(i)->result(stat->params);
} }
#endif #endif
@ -1986,7 +1987,7 @@ class Node : public RefCounted
* Return the number of nodes in the subtree starting at this node. * Return the number of nodes in the subtree starting at this node.
* @return the number of nodes in this subtree. * @return the number of nodes in this subtree.
*/ */
virtual size_t size() const = 0; virtual size_type size() const = 0;
/** /**
* Return the result vector of this subtree. * Return the result vector of this subtree.
* @return The result vector of this subtree. * @return The result vector of this subtree.
@ -2025,7 +2026,7 @@ class ScalarStatNode : public Node
virtual Result total() const { return data->result(); }; virtual Result total() const { return data->result(); };
virtual size_t size() const { return 1; } virtual size_type size() const { return 1; }
/** /**
* *
@ -2058,7 +2059,7 @@ class ScalarProxyNode : public Node
return proxy.result(); return proxy.result();
} }
virtual size_t virtual size_type
size() const size() const
{ {
return 1; return 1;
@ -2084,7 +2085,7 @@ class VectorStatNode : public Node
virtual const VResult &result() const { return data->result(); } virtual const VResult &result() const { return data->result(); }
virtual Result total() const { return data->total(); }; virtual Result total() const { return data->total(); };
virtual size_t size() const { return data->size(); } virtual size_type size() const { return data->size(); }
virtual std::string str() const { return data->name; } virtual std::string str() const { return data->name; }
}; };
@ -2099,7 +2100,7 @@ class ConstNode : public Node
ConstNode(T s) : vresult(1, (Result)s) {} ConstNode(T s) : vresult(1, (Result)s) {}
const VResult &result() const { return vresult; } const VResult &result() const { return vresult; }
virtual Result total() const { return vresult[0]; }; virtual Result total() const { return vresult[0]; };
virtual size_t size() const { return 1; } virtual size_type size() const { return 1; }
virtual std::string str() const { return to_string(vresult[0]); } virtual std::string str() const { return to_string(vresult[0]); }
}; };
@ -2116,20 +2117,20 @@ class ConstVectorNode : public Node
virtual Result virtual Result
total() const total() const
{ {
int size = this->size(); size_type size = this->size();
Result tmp = 0; Result tmp = 0;
for (int i = 0; i < size; i++) for (off_type i = 0; i < size; i++)
tmp += vresult[i]; tmp += vresult[i];
return tmp; return tmp;
} }
virtual size_t size() const { return vresult.size(); } virtual size_type size() const { return vresult.size(); }
virtual std::string virtual std::string
str() const str() const
{ {
int size = this->size(); size_type size = this->size();
std::string tmp = "("; std::string tmp = "(";
for (int i = 0; i < size; i++) for (off_type i = 0; i < size; i++)
tmp += csprintf("%s ",to_string(vresult[i])); tmp += csprintf("%s ",to_string(vresult[i]));
tmp += ")"; tmp += ")";
return tmp; return tmp;
@ -2189,13 +2190,13 @@ class UnaryNode : public Node
result() const result() const
{ {
const VResult &lvec = l->result(); const VResult &lvec = l->result();
int size = lvec.size(); size_type size = lvec.size();
assert(size > 0); assert(size > 0);
vresult.resize(size); vresult.resize(size);
Op op; Op op;
for (int i = 0; i < size; ++i) for (off_type i = 0; i < size; ++i)
vresult[i] = op(lvec[i]); vresult[i] = op(lvec[i]);
return vresult; return vresult;
@ -2206,12 +2207,12 @@ class UnaryNode : public Node
{ {
const VResult &vec = this->result(); const VResult &vec = this->result();
Result total = 0; Result total = 0;
for (int i = 0; i < size(); i++) for (off_type i = 0; i < size(); i++)
total += vec[i]; total += vec[i];
return total; return total;
} }
virtual size_t size() const { return l->size(); } virtual size_type size() const { return l->size(); }
virtual std::string virtual std::string
str() const str() const
@ -2244,19 +2245,19 @@ class BinaryNode : public Node
vresult.resize(1); vresult.resize(1);
vresult[0] = op(lvec[0], rvec[0]); vresult[0] = op(lvec[0], rvec[0]);
} else if (lvec.size() == 1) { } else if (lvec.size() == 1) {
int size = rvec.size(); size_type size = rvec.size();
vresult.resize(size); vresult.resize(size);
for (int i = 0; i < size; ++i) for (off_type i = 0; i < size; ++i)
vresult[i] = op(lvec[0], rvec[i]); vresult[i] = op(lvec[0], rvec[i]);
} else if (rvec.size() == 1) { } else if (rvec.size() == 1) {
int size = lvec.size(); size_type size = lvec.size();
vresult.resize(size); vresult.resize(size);
for (int i = 0; i < size; ++i) for (off_type i = 0; i < size; ++i)
vresult[i] = op(lvec[i], rvec[0]); vresult[i] = op(lvec[i], rvec[0]);
} else if (rvec.size() == lvec.size()) { } else if (rvec.size() == lvec.size()) {
int size = rvec.size(); size_type size = rvec.size();
vresult.resize(size); vresult.resize(size);
for (int i = 0; i < size; ++i) for (off_type i = 0; i < size; ++i)
vresult[i] = op(lvec[i], rvec[i]); vresult[i] = op(lvec[i], rvec[i]);
} }
@ -2268,16 +2269,16 @@ class BinaryNode : public Node
{ {
const VResult &vec = this->result(); const VResult &vec = this->result();
Result total = 0; Result total = 0;
for (int i = 0; i < size(); i++) for (off_type i = 0; i < size(); i++)
total += vec[i]; total += vec[i];
return total; return total;
} }
virtual size_t virtual size_type
size() const size() const
{ {
int ls = l->size(); size_type ls = l->size();
int rs = r->size(); size_type rs = r->size();
if (ls == 1) { if (ls == 1) {
return rs; return rs;
} else if (rs == 1) { } else if (rs == 1) {
@ -2309,13 +2310,13 @@ class SumNode : public Node
result() const result() const
{ {
const VResult &lvec = l->result(); const VResult &lvec = l->result();
int size = lvec.size(); size_type size = lvec.size();
assert(size > 0); assert(size > 0);
vresult[0] = 0.0; vresult[0] = 0.0;
Op op; Op op;
for (int i = 0; i < size; ++i) for (off_type i = 0; i < size; ++i)
vresult[0] = op(vresult[0], lvec[i]); vresult[0] = op(vresult[0], lvec[i]);
return vresult; return vresult;
@ -2325,19 +2326,19 @@ class SumNode : public Node
total() const total() const
{ {
const VResult &lvec = l->result(); const VResult &lvec = l->result();
int size = lvec.size(); size_type size = lvec.size();
assert(size > 0); assert(size > 0);
Result vresult = 0.0; Result vresult = 0.0;
Op op; Op op;
for (int i = 0; i < size; ++i) for (off_type i = 0; i < size; ++i)
vresult = op(vresult, lvec[i]); vresult = op(vresult, lvec[i]);
return vresult; return vresult;
} }
virtual size_t size() const { return 1; } virtual size_type size() const { return 1; }
virtual std::string virtual std::string
str() const str() const
@ -2452,7 +2453,7 @@ class Vector : public WrapVec<Vector<N>, VectorBase<StatStor>, VectorStatData>
* @return A reference to this stat. * @return A reference to this stat.
*/ */
Vector & Vector &
init(size_t size) init(size_type size)
{ {
this->doInit(size); this->doInit(size);
return *this; return *this;
@ -2474,7 +2475,7 @@ class AverageVector
* @return A reference to this stat. * @return A reference to this stat.
*/ */
AverageVector & AverageVector &
init(size_t size) init(size_type size)
{ {
this->doInit(size); this->doInit(size);
return *this; return *this;
@ -2491,7 +2492,7 @@ class Vector2d
{ {
public: public:
Vector2d & Vector2d &
init(size_t x, size_t y) init(size_type x, size_type y)
{ {
this->doInit(x, y); this->doInit(x, y);
return *this; return *this;
@ -2526,7 +2527,7 @@ class Distribution
this->params.min = min; this->params.min = min;
this->params.max = max; this->params.max = max;
this->params.bucket_size = bkt; this->params.bucket_size = bkt;
this->params.size = (int)rint((max - min) / bkt + 1.0); this->params.size = (size_type)rint((max - min) / bkt + 1.0);
this->doInit(); this->doInit();
return *this; return *this;
} }
@ -2606,12 +2607,12 @@ class VectorDistribution
* @return A reference to this distribution. * @return A reference to this distribution.
*/ */
VectorDistribution & VectorDistribution &
init(int size, Counter min, Counter max, Counter bkt) init(size_type size, Counter min, Counter max, Counter bkt)
{ {
this->params.min = min; this->params.min = min;
this->params.max = max; this->params.max = max;
this->params.bucket_size = bkt; this->params.bucket_size = bkt;
this->params.size = (int)rint((max - min) / bkt + 1.0); this->params.size = rint((max - min) / bkt + 1.0);
this->doInit(size); this->doInit(size);
return *this; return *this;
} }
@ -2640,7 +2641,7 @@ class VectorStandardDeviation
* @return A reference to this distribution. * @return A reference to this distribution.
*/ */
VectorStandardDeviation & VectorStandardDeviation &
init(int size) init(size_type size)
{ {
this->doInit(size); this->doInit(size);
return *this; return *this;
@ -2670,7 +2671,7 @@ class VectorAverageDeviation
* @return A reference to this distribution. * @return A reference to this distribution.
*/ */
VectorAverageDeviation & VectorAverageDeviation &
init(int size) init(size_type size)
{ {
this->doInit(size); this->doInit(size);
return *this; return *this;
@ -2714,7 +2715,7 @@ class FormulaBase : public DataAccess
/** /**
* Return the number of elements in the tree. * Return the number of elements in the tree.
*/ */
size_t size() const; size_type size() const;
bool check() const { return true; } bool check() const { return true; }
@ -2757,7 +2758,7 @@ class FormulaStatData : public FormulaData
virtual bool zero() const { return s.zero(); } virtual bool zero() const { return s.zero(); }
virtual void reset() { s.reset(); } virtual void reset() { s.reset(); }
virtual size_t size() const { return s.size(); } virtual size_type size() const { return s.size(); }
virtual const VResult & virtual const VResult &
result() const result() const
@ -2822,7 +2823,7 @@ class FormulaNode : public Node
public: public:
FormulaNode(const Formula &f) : formula(f) {} FormulaNode(const Formula &f) : formula(f) {}
virtual size_t size() const { return formula.size(); } virtual size_type size() const { return formula.size(); }
virtual const VResult &result() const { formula.result(vec); return vec; } virtual const VResult &result() const { formula.result(vec); return vec; }
virtual Result total() const { return formula.total(); } virtual Result total() const { return formula.total(); }

View file

@ -568,7 +568,7 @@ MySql::configure(const VectorData &data)
InsertSubData subdata; InsertSubData subdata;
subdata.stat = statid; subdata.stat = statid;
subdata.y = 0; subdata.y = 0;
for (int i = 0; i < data.subnames.size(); ++i) { for (off_type i = 0; i < data.subnames.size(); ++i) {
subdata.x = i; subdata.x = i;
subdata.name = data.subnames[i]; subdata.name = data.subnames[i];
subdata.descr = data.subdescs.empty() ? "" : data.subdescs[i]; subdata.descr = data.subdescs.empty() ? "" : data.subdescs[i];
@ -615,7 +615,7 @@ MySql::configure(const VectorDistData &data)
InsertSubData subdata; InsertSubData subdata;
subdata.stat = statid; subdata.stat = statid;
subdata.y = 0; subdata.y = 0;
for (int i = 0; i < data.subnames.size(); ++i) { for (off_type i = 0; i < data.subnames.size(); ++i) {
subdata.x = i; subdata.x = i;
subdata.name = data.subnames[i]; subdata.name = data.subnames[i];
subdata.descr = data.subdescs.empty() ? "" : data.subdescs[i]; subdata.descr = data.subdescs.empty() ? "" : data.subdescs[i];
@ -639,7 +639,7 @@ MySql::configure(const Vector2dData &data)
InsertSubData subdata; InsertSubData subdata;
subdata.stat = statid; subdata.stat = statid;
subdata.y = -1; subdata.y = -1;
for (int i = 0; i < data.subnames.size(); ++i) { for (off_type i = 0; i < data.subnames.size(); ++i) {
subdata.x = i; subdata.x = i;
subdata.name = data.subnames[i]; subdata.name = data.subnames[i];
subdata.descr = data.subdescs.empty() ? "" : data.subdescs[i]; subdata.descr = data.subdescs.empty() ? "" : data.subdescs[i];
@ -653,7 +653,7 @@ MySql::configure(const Vector2dData &data)
subdata.stat = statid; subdata.stat = statid;
subdata.x = -1; subdata.x = -1;
subdata.descr = ""; subdata.descr = "";
for (int i = 0; i < data.y_subnames.size(); ++i) { for (off_type i = 0; i < data.y_subnames.size(); ++i) {
subdata.y = i; subdata.y = i;
subdata.name = data.y_subnames[i]; subdata.name = data.y_subnames[i];
if (!subdata.name.empty()) if (!subdata.name.empty())
@ -760,8 +760,8 @@ MySql::output(const VectorData &data)
newdata.y = 0; newdata.y = 0;
const VCounter &cvec = data.value(); const VCounter &cvec = data.value();
int size = data.size(); size_type size = data.size();
for (int x = 0; x < size; x++) { for (off_type x = 0; x < size; x++) {
newdata.x = x; newdata.x = x;
newdata.data = cvec[x]; newdata.data = cvec[x];
newdata.insert(); newdata.insert();
@ -808,8 +808,8 @@ MySql::output(const DistDataData &data)
newdata.data = data.overflow; newdata.data = data.overflow;
newdata.insert(); newdata.insert();
int size = data.cvec.size(); size_type size = data.cvec.size();
for (int x = 0; x < size; x++) { for (off_type x = 0; x < size; x++) {
newdata.x = x; newdata.x = x;
newdata.data = data.cvec[x]; newdata.data = data.cvec[x];
newdata.insert(); newdata.insert();
@ -837,8 +837,8 @@ MySql::output(const VectorDistData &data)
newdata.stat = find(data.id); newdata.stat = find(data.id);
int size = data.data.size(); size_type size = data.data.size();
for (int y = 0; y < size; ++y) { for (off_type y = 0; y < size; ++y) {
newdata.y = y; newdata.y = y;
output(data.data[y]); output(data.data[y]);
} }
@ -852,10 +852,10 @@ MySql::output(const Vector2dData &data)
newdata.stat = find(data.id); newdata.stat = find(data.id);
int index = 0; off_type index = 0;
for (int x = 0; x < data.x; x++) { for (off_type x = 0; x < data.x; x++) {
newdata.x = x; newdata.x = x;
for (int y = 0; y < data.y; y++) { for (off_type y = 0; y < data.y; y++) {
newdata.y = y; newdata.y = y;
newdata.data = data.cvec[index++]; newdata.data = data.cvec[index++];
newdata.insert(); newdata.insert();

View file

@ -69,9 +69,9 @@ class InsertData
{ {
private: private:
char *query; char *query;
int size; size_type size;
bool first; bool first;
static const int maxsize = 1024*1024; static const size_type maxsize = 1024*1024;
public: public:
MySqlRun *run; MySqlRun *run;
@ -95,9 +95,9 @@ class InsertEvent
{ {
private: private:
char *query; char *query;
int size; size_type size;
bool first; bool first;
static const int maxsize = 1024*1024; static const size_type maxsize = 1024*1024;
typedef std::map<std::string, uint32_t> event_map_t; typedef std::map<std::string, uint32_t> event_map_t;
event_map_t events; event_map_t events;

View file

@ -239,11 +239,11 @@ struct VectorPrint
void void
VectorPrint::operator()(std::ostream &stream) const VectorPrint::operator()(std::ostream &stream) const
{ {
int _size = vec.size(); size_type _size = vec.size();
Result _total = 0.0; Result _total = 0.0;
if (flags & (pdf | cdf)) { if (flags & (pdf | cdf)) {
for (int i = 0; i < _size; ++i) { for (off_type i = 0; i < _size; ++i) {
_total += vec[i]; _total += vec[i];
} }
} }
@ -266,7 +266,7 @@ VectorPrint::operator()(std::ostream &stream) const
print.value = vec[0]; print.value = vec[0];
print(stream); print(stream);
} else if (!compat) { } else if (!compat) {
for (int i = 0; i < _size; ++i) { for (off_type i = 0; i < _size; ++i) {
if (havesub && (i >= subnames.size() || subnames[i].empty())) if (havesub && (i >= subnames.size() || subnames[i].empty()))
continue; continue;
@ -298,7 +298,7 @@ VectorPrint::operator()(std::ostream &stream) const
Result _cdf = 0.0; Result _cdf = 0.0;
if (flags & dist) { if (flags & dist) {
ccprintf(stream, "%s.start_dist\n", name); ccprintf(stream, "%s.start_dist\n", name);
for (int i = 0; i < _size; ++i) { for (off_type i = 0; i < _size; ++i) {
print.name = havesub ? subnames[i] : to_string(i); print.name = havesub ? subnames[i] : to_string(i);
print.desc = subdescs.empty() ? desc : subdescs[i]; print.desc = subdescs.empty() ? desc : subdescs[i];
print.flags |= __substat; print.flags |= __substat;
@ -318,7 +318,7 @@ VectorPrint::operator()(std::ostream &stream) const
} }
ccprintf(stream, "%s.end_dist\n", name); ccprintf(stream, "%s.end_dist\n", name);
} else { } else {
for (int i = 0; i < _size; ++i) { for (off_type i = 0; i < _size; ++i) {
if (havesub && subnames[i].empty()) if (havesub && subnames[i].empty())
continue; continue;
@ -366,7 +366,7 @@ struct DistPrint
Counter min; Counter min;
Counter max; Counter max;
Counter bucket_size; Counter bucket_size;
int size; size_type size;
bool fancy; bool fancy;
void operator()(ostream &stream) const; void operator()(ostream &stream) const;
@ -407,7 +407,7 @@ DistPrint::operator()(ostream &stream) const
Result total = 0.0; Result total = 0.0;
total += underflow; total += underflow;
for (int i = 0; i < size; ++i) for (off_type i = 0; i < size; ++i)
total += vec[i]; total += vec[i];
total += overflow; total += overflow;
@ -448,7 +448,7 @@ DistPrint::operator()(ostream &stream) const
} }
if (!compat) { if (!compat) {
for (int i = 0; i < size; ++i) { for (off_type i = 0; i < size; ++i) {
stringstream namestr; stringstream namestr;
namestr << name; namestr << name;
@ -473,7 +473,7 @@ DistPrint::operator()(ostream &stream) const
print.flags = flags | __substat; print.flags = flags | __substat;
for (int i = 0; i < size; ++i) { for (off_type i = 0; i < size; ++i) {
if ((flags & nozero && vec[i] == 0.0) || if ((flags & nozero && vec[i] == 0.0) ||
(flags & nonan && isnan(vec[i]))) (flags & nonan && isnan(vec[i])))
continue; continue;
@ -560,7 +560,7 @@ Text::visit(const VectorData &data)
if (noOutput(data)) if (noOutput(data))
return; return;
int size = data.size(); size_type size = data.size();
VectorPrint print; VectorPrint print;
print.name = data.name; print.name = data.name;
@ -573,11 +573,11 @@ Text::visit(const VectorData &data)
print.total = data.total(); print.total = data.total();
if (!data.subnames.empty()) { if (!data.subnames.empty()) {
for (int i = 0; i < size; ++i) { for (off_type i = 0; i < size; ++i) {
if (!data.subnames[i].empty()) { if (!data.subnames[i].empty()) {
print.subnames = data.subnames; print.subnames = data.subnames;
print.subnames.resize(size); print.subnames.resize(size);
for (int i = 0; i < size; ++i) { for (off_type i = 0; i < size; ++i) {
if (!data.subnames[i].empty() && if (!data.subnames[i].empty() &&
!data.subdescs[i].empty()) { !data.subdescs[i].empty()) {
print.subdescs = data.subdescs; print.subdescs = data.subdescs;
@ -609,22 +609,22 @@ Text::visit(const Vector2dData &data)
print.precision = data.precision; print.precision = data.precision;
if (!data.subnames.empty()) { if (!data.subnames.empty()) {
for (int i = 0; i < data.x; ++i) for (off_type i = 0; i < data.x; ++i)
if (!data.subnames[i].empty()) if (!data.subnames[i].empty())
havesub = true; havesub = true;
} }
VResult tot_vec(data.y); VResult tot_vec(data.y);
Result super_total = 0.0; Result super_total = 0.0;
for (int i = 0; i < data.x; ++i) { for (off_type i = 0; i < data.x; ++i) {
if (havesub && (i >= data.subnames.size() || data.subnames[i].empty())) if (havesub && (i >= data.subnames.size() || data.subnames[i].empty()))
continue; continue;
int iy = i * data.y; off_type iy = i * data.y;
VResult yvec(data.y); VResult yvec(data.y);
Result total = 0.0; Result total = 0.0;
for (int j = 0; j < data.y; ++j) { for (off_type j = 0; j < data.y; ++j) {
yvec[j] = data.cvec[iy + j]; yvec[j] = data.cvec[iy + j];
tot_vec[j] += yvec[j]; tot_vec[j] += yvec[j];
total += yvec[j]; total += yvec[j];
@ -668,7 +668,7 @@ Text::visit(const DistData &data)
print.underflow = data.data.underflow; print.underflow = data.data.underflow;
print.overflow = data.data.overflow; print.overflow = data.data.overflow;
print.vec.resize(data.data.cvec.size()); print.vec.resize(data.data.cvec.size());
for (int i = 0; i < print.vec.size(); ++i) for (off_type i = 0; i < print.vec.size(); ++i)
print.vec[i] = (Result)data.data.cvec[i]; print.vec[i] = (Result)data.data.cvec[i];
print.sum = data.data.sum; print.sum = data.data.sum;
print.squares = data.data.squares; print.squares = data.data.squares;
@ -689,7 +689,7 @@ Text::visit(const VectorDistData &data)
if (noOutput(data)) if (noOutput(data))
return; return;
for (int i = 0; i < data.size(); ++i) { for (off_type i = 0; i < data.size(); ++i) {
DistPrint print; DistPrint print;
print.name = data.name + "_" + print.name = data.name + "_" +
@ -705,7 +705,7 @@ Text::visit(const VectorDistData &data)
print.underflow = data.data[i].underflow; print.underflow = data.data[i].underflow;
print.overflow = data.data[i].overflow; print.overflow = data.data[i].overflow;
print.vec.resize(data.data[i].cvec.size()); print.vec.resize(data.data[i].cvec.size());
for (int j = 0; j < print.vec.size(); ++j) for (off_type j = 0; j < print.vec.size(); ++j)
print.vec[j] = (Result)data.data[i].cvec[j]; print.vec[j] = (Result)data.data[i].cvec[j];
print.sum = data.data[i].sum; print.sum = data.data[i].sum;
print.squares = data.data[i].squares; print.squares = data.data[i].squares;

View file

@ -47,6 +47,9 @@ typedef double Result;
/** vector of results. */ /** vector of results. */
typedef std::vector<Result> VResult; typedef std::vector<Result> VResult;
typedef unsigned int size_type;
typedef unsigned int off_type;
/* namespace Stats */ } /* namespace Stats */ }
#endif // __BASE_STATS_TYPES_HH__ #endif // __BASE_STATS_TYPES_HH__