Changeset 41


Ignore:
Timestamp:
Jan 13, 2006, 5:41:57 PM (16 years ago)
Author:
Peter Johansson
Message:

inserted zeros in vectors returned from Stats::accumulated
so they are equally sized.

Location:
trunk/lib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Stats.cc

    r39 r41  
    88#include <fstream>
    99
     10#include <algorithm>
    1011#include <map>
    1112#include <numeric>
     
    2122
    2223  Gnuplot Stats::gnuplot_pipe_;
     24  u_int Stats::latest_revision_=0;
    2325
    2426  std::vector<double> Stats::accumulated(void) const
     
    2830
    2931    // sum of all users
    30     std::vector<u_int> sum;
     32    std::vector<u_int> sum(latest_revision_+1,0);
    3133    sum=std::accumulate(map_.begin(), map_.end(), sum,
    3234                        PairValuePlus<std::string,u_int>());
     
    4345      return std::vector<double>();
    4446    std::vector<u_int> vec=(map_.find(user))->second;
     47 
     48    vec.reserve(latest_revision_+1);
     49    if (vec.size() < latest_revision_+1)
     50      vec.insert(vec.end(), latest_revision_+1-vec.size(), 0);
    4551
    4652    std::vector<double> accum(vec.size());
     
    5864        vec[i]=0;
    5965      vec[rev]=1;
     66      latest_revision_ = std::max(latest_revision_,rev);
    6067    }
    6168    else
  • trunk/lib/Stats.h

    r38 r41  
    7272    std::string plot(void) const;
    7373
     74    static u_int latest_revision_; // latest rev. for whole project
     75
    7476    // Peter, if the vector is sparse make it a map
    7577    typedef std::map<std::string, std::vector<u_int> > Map_;
Note: See TracChangeset for help on using the changeset viewer.