Changeset 1208


Ignore:
Timestamp:
Oct 7, 2010, 5:33:36 AM (10 years ago)
Author:
Peter Johansson
Message:

Changed value type of SparseVector? to be (signed) int. Use
Vector::iterator when printing Vector's data instead of using
operator[]
refs #475

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Stats.cc

    r1205 r1208  
    556556    for (A2VConstIter i(m.begin()); i!=m.end(); ++i){
    557557      os << i->first << "\n";
    558       if (i->second[0])
    559         os << 0 << " " << i->second[0] << " ";
    560       // FIXME: ise Vector::iterator
    561       for (size_t j=1; j<i->second.size(); ++j) {
    562         // only print if stats changes in this rev
    563         if (i->second[j] != i->second[j-1]) {
    564           os << j << " " << i->second[j] - i->second[j-1] << " ";
     558      const SumVector& vec = i->second;
     559      if (vec.size()) {
     560        SumVector::const_iterator v = vec.begin();
     561        if (v->second)
     562          os << v->first << " " << v->second << " ";
     563        ++v;
     564        SumVector::const_iterator prev = vec.begin();
     565        while (v != vec.end()) {
     566          assert(vec[v->first - 1] == prev->second);
     567          // FIXME: this if should not be needed if SumVector was
     568          // truly sparse and collapsed when possible.
     569          if (v->second != prev->second)
     570            os << v->first << " " << v->second - prev->second << " ";
     571          ++v;
     572          ++prev;
    565573        }
    566574      }
  • trunk/lib/Vector.cc

    r1194 r1208  
    2929  {
    3030    result.clear();
    31     unsigned int value = 0;
    32     for (SumVector::const_iterator iter = vec.begin(); iter!=vec.end();++iter) {
     31    int value = 0;
     32    for (SparseVector::const_iterator iter = vec.begin();
     33         iter!=vec.end();++iter) {
    3334      value += iter->second;
     35      assert(value>=0);
    3436      result.set(iter->first, value);
    3537    }
  • trunk/lib/Vector.h

    r1203 r1208  
    211211  };
    212212
    213   typedef Vector<unsigned int, SparsePolicy<unsigned int> > SparseVector;
     213  typedef Vector<int, SparsePolicy<int> > SparseVector;
    214214
    215215  template<typename T>
  • trunk/test/stats.cc

    r1164 r1208  
    194194    stats2.print(out2);
    195195   
    196     if (out.str()!=out2.str()) {
     196    if ( test::diff(out.str(),out2.str()) ) {
    197197      std::cout << "test_cache() failed\n";
    198198      return false;
Note: See TracChangeset for help on using the changeset viewer.