- Timestamp:
- Oct 4, 2010, 1:39:12 AM (10 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/AddStats.cc
r1003 r1194 54 54 void AddStats::do_parse(const std::string& path, svn_revnum_t rev) 55 55 { 56 // FIXME: why not using the log from File object 56 57 SVNlog log(path); 57 58 typedef std::set<svn_revnum_t, std::greater<svn_revnum_t> > RevSet; 58 59 RevSet revs; 60 std::vector<std::map<std::string, SparseVector> > data; 59 61 std::transform(log.commits().begin(), log.commits().end(), 60 62 std::inserter(revs, revs.begin()), … … 64 66 SVNblame svn_blame(path, *rev_iter); 65 67 LineTypeParser parser(path); 68 std::vector<size_t> add_vec(4,0); 69 std::string author=""; 66 70 while (svn_blame.valid()) { 67 71 LineTypeParser::line_type lt = parser.parse(svn_blame.line()); 68 if (*rev_iter==svn_blame.revision()) 69 add(svn_blame.author(), *rev_iter, lt); 72 if (*rev_iter==svn_blame.revision()) { 73 author = svn_blame.author(); 74 assert(lt<add_vec.size()); 75 ++add_vec[lt]; 76 } 70 77 // I dont trust blame and log behave consistently (stop-on-copy). 71 78 revs.insert(svn_blame.revision()); 72 79 svn_blame.next_line(); 73 80 } 81 if (author.empty()) { // don't add 0 to author "" 82 assert(add_vec[0]==0); 83 assert(add_vec[1]==0); 84 assert(add_vec[2]==0); 85 assert(add_vec[3]==0); 86 continue; 87 } 88 if (data.size()<add_vec.size()) 89 data.resize(add_vec.size()); 90 for (size_t lt=0; lt<add_vec.size(); ++lt) { 91 assert(author.size()); 92 SparseVector& vec=data[lt][author]; 93 // add add_vec[lt] to current value 94 vec.set(*rev_iter, vec[*rev_iter] + add_vec[lt]); 95 assert(data[lt][author][*rev_iter] >= add_vec[lt]); 96 } 74 97 } 75 accumulate_stats(rev); 98 // add parsed data to member 99 add(data); 76 100 } 77 101 78 102 79 unsigned int AddStats::max_element(const std::vector<unsigned int>& v) const103 unsigned int AddStats::max_element(const SumVector& v) const 80 104 { 81 105 assert(v.size()); -
trunk/lib/AddStats.h
r1003 r1194 45 45 private: 46 46 void do_parse(const std::string&, svn_revnum_t); 47 unsigned int max_element(const std::vector<unsigned int>&) const;47 unsigned int max_element(const SumVector&) const; 48 48 49 49 }; -
trunk/lib/BlameStats.cc
r1036 r1194 29 29 #include "SVNlog.h" 30 30 #include "utility.h" 31 #include "Vector.h" 31 32 32 33 #include <algorithm> … … 62 63 63 64 64 void BlameStats::fill_in(Author2Vector& a2v, svn_revnum_t rev)65 {66 if (rev==0)67 return;68 for (std::set<std::string>::const_iterator iter(authors().begin());69 iter!=authors().end(); ++iter) {70 std::vector<unsigned int>& vec = a2v[*iter];71 vec.resize(revision()+1);72 assert(rev<static_cast<svn_revnum_t>(vec.size()));73 vec[rev]=vec[rev-1];74 }75 }76 77 78 65 void BlameStats::do_parse(const std::string& path, svn_revnum_t first_rev) 79 66 { 67 // FIXME: using log from File object 80 68 SVNlog log(path); 81 69 typedef std::set<svn_revnum_t> RevSet; … … 84 72 std::inserter(revs, revs.begin()), 85 73 std::mem_fun_ref(&Commitment::revision)); 74 // we use a ParseVector here to be able to detect when people are 75 // absent in a revision. 76 std::vector<std::map<std::string, SparseVector> > data(4); 86 77 for (RevSet::reverse_iterator rev_iter=revs.rbegin(); 87 78 rev_iter!=revs.rend() && *rev_iter>=first_rev; ++rev_iter){ … … 89 80 LineTypeParser parser(path); 90 81 while (svn_blame.valid()) { 91 add(svn_blame.author(), *rev_iter, parser.parse(svn_blame.line())); 92 // I dont trust blame and log behave consistent (stop-on-copy). 82 int lt = parser.parse(svn_blame.line()); 83 assert(lt<data.size()); 84 SparseVector& vec = data[lt][svn_blame.author()]; 85 vec.set(*rev_iter, vec[*rev_iter] + 1); 86 add_author(svn_blame.author()); 87 // I dont trust blame and log behave consistently (stop-on-copy). 93 88 revs.insert(svn_blame.revision()); 94 89 svn_blame.next_line(); 95 90 } 96 91 } 97 98 // filling in pristine revisions, i.e., revs that are larger than 99 // first_rev and not occuring in revs. 100 RevSet::iterator rev_iter=revs.begin(); 101 svn_revnum_t rev = first_rev; 102 while (rev<=revision()) { 103 if (rev_iter!=revs.end() && rev>*rev_iter) 104 ++rev_iter; 105 else if (rev_iter!=revs.end() && rev==*rev_iter) { 106 ++rev_iter; 107 ++rev; 108 } 109 else { 110 fill_in(code_stats(),rev); 111 fill_in(comment_stats(),rev); 112 fill_in(other_stats(),rev); 113 fill_in(copyright_stats(),rev); 114 ++rev; 92 93 // for count=zero we have not created an entry in SumVector and 94 // value will be "value for previous rev". Therefore we need to 95 // set the value to zero explicitely. 96 if (stats_.size()<data.size()) 97 stats_.resize(data.size()); 98 for (int lt =0; lt<data.size(); ++lt) { 99 // just to avoid long long lines 100 typedef std::map<std::string,SparseVector>::const_iterator const_iterator; 101 for (const_iterator av = data[lt].begin(); av!=data[lt].end(); ++av) { 102 for (RevSet::const_reverse_iterator rev_iter=revs.rbegin(); 103 rev_iter!=revs.rend() && *rev_iter >= first_rev; ++rev_iter) { 104 // FIXME: use Vector::iterator to avoid logN checkup 105 stats_[lt][av->first].set(*rev_iter, data[lt][av->first][*rev_iter]); 106 } 115 107 } 116 108 } 117 109 } 118 110 119 120 111 }} // end of namespace svndigest and namespace theplu -
trunk/lib/BlameStats.h
r1036 r1194 45 45 private: 46 46 void do_parse(const std::string&, svn_revnum_t); 47 void fill_in(Author2Vector&, svn_revnum_t rev);47 //void fill_in(Author2Vector&, svn_revnum_t rev); 48 48 49 49 }; -
trunk/lib/ClassicStats.cc
r1036 r1194 65 65 LineTypeParser parser(path); 66 66 SVNblame svn_blame(path); 67 std::vector<std::map<std::string, SparseVector> > data(4); 67 68 while (svn_blame.valid()) { 68 add(svn_blame.author(), svn_blame.revision(), 69 parser.parse(svn_blame.line())); 69 LineTypeParser::line_type lt = parser.parse(svn_blame.line()); 70 assert(lt<data.size()); 71 SparseVector& vec = data[lt][svn_blame.author()]; 72 vec.set(svn_blame.revision(), vec[svn_blame.revision()] + 1); 70 73 svn_blame.next_line(); 71 74 } 72 accumulate_stats(); 75 // add parsed data to member 76 add(data); 73 77 } 74 78 75 79 76 80 unsigned int 77 ClassicStats::max_element(const std::vector<unsigned int>& v) const81 ClassicStats::max_element(const SumVector& v) const 78 82 { 79 83 assert(v.size()); -
trunk/lib/ClassicStats.h
r1036 r1194 45 45 private: 46 46 void do_parse(const std::string&, svn_revnum_t); 47 unsigned int max_element(const std::vector<unsigned int>&) const;47 unsigned int max_element(const SumVector&) const; 48 48 49 49 }; -
trunk/lib/Functor.h
r978 r1194 186 186 template <typename Key, typename T> 187 187 struct PairValuePlus : 188 public std::binary_function<std::vector<T>, 189 std::pair<const Key, std::vector<T> >, 190 std::vector<T> > 188 public std::binary_function<T, std::pair<const Key, T>, T> 191 189 { 192 std::vector<T> operator()(const std::vector<T>& sum, 193 const std::pair<const Key,std::vector<T> >& p) 190 T operator()(const T& sum, const std::pair<const Key, T>& p) 194 191 { 195 return VectorPlus<T>()(sum, p.second);192 return sum + p.second; 196 193 } 197 194 }; -
trunk/lib/Graph.cc
r1182 r1194 85 85 86 86 87 void Graph::plot(const std::vector<unsigned int>& y, const std::string& label,87 void Graph::plot(const SumVector& y, const std::string& label, 88 88 unsigned int lines) 89 89 { … … 116 116 117 117 pls_.col0(1); 118 // FIXME: loop over segments instead of revs, i.e., use Vector::iterator 118 119 for (unsigned int i=1; i<y.size(); ++i) { 119 120 PLFLT x0=i-1; -
trunk/lib/Graph.h
r1017 r1194 25 25 26 26 #include <config.h> 27 28 #include "Vector.h" 27 29 28 30 #include <string> … … 91 93 legend entry, and so on. 92 94 */ 93 void plot(const std::vector<unsigned int>& data, const std::string& label,95 void plot(const SumVector& data, const std::string& label, 94 96 unsigned int lines); 95 97 -
trunk/lib/Makefile.am
r1187 r1194 48 48 OptionVersion.cc \ 49 49 rmdirhier.cc Stats.cc StatsCollection.cc subversion_info.cc SVN.cc \ 50 SVNblame.cc SVNdiff.cc SVNinfo.cc SVNlog.cc SVNproperty.cc Trac.cc utility.cc 50 SVNblame.cc SVNdiff.cc SVNinfo.cc SVNlog.cc SVNproperty.cc \ 51 Trac.cc utility.cc Vector.cc 51 52 52 53 -
trunk/lib/Stats.cc
r1124 r1194 46 46 #include <vector> 47 47 48 49 48 namespace theplu{ 50 49 namespace svndigest{ … … 79 78 } 80 79 81 80 81 void Stats::add(const std::vector<std::map<std::string, SparseVector> >& data) 82 { 83 // loop over line types 84 for (size_t lt = 0; lt<data.size(); ++lt) { 85 std::map<std::string, SparseVector>::const_iterator iter=data[lt].begin(); 86 std::map<std::string, SparseVector>::const_iterator last=data[lt].end(); 87 // loop over users 88 for ( ; iter!=last; ++iter) { 89 add_author(iter->first); 90 SumVector tmpvec; 91 accumulate(iter->second, tmpvec); 92 stats_[lt][iter->first] += tmpvec; 93 } 94 } 95 } 96 97 98 /* 82 99 void Stats::accumulate(std::vector<unsigned int>& vec, 83 100 svn_revnum_t rev) const … … 94 111 vec.resize(revision()+1, vec.back()); 95 112 } 96 97 113 */ 114 /* 98 115 void Stats::accumulate_stats(svn_revnum_t rev) 99 116 { … … 112 129 } 113 130 } 114 115 116 void Stats::add(const std::string& user, const unsigned int&rev,117 const LineTypeParser::line_type<, unsigned int n)131 */ 132 /* 133 void Stats::add(const std::string& user, svn_revnum_t rev, 134 LineTypeParser::line_type lt, unsigned int n) 118 135 { 119 136 assert(user.size()); 120 137 add_author(user); 121 138 122 add(code_stats()[user], rev, lt==LineTypeParser::code, n); 123 add(comment_stats()[user], rev, lt==LineTypeParser::comment, n); 124 add(other_stats()[user], rev, lt==LineTypeParser::other, n); 125 add(copyright_stats()[user], rev, lt==LineTypeParser::copyright, n); 139 if (lt==LineTypeParser::code) 140 add(code_stats()[user], rev, n); 141 else if (lt==LineTypeParser::comment) 142 add(comment_stats()[user], rev, n); 143 else if (lt==LineTypeParser::other) 144 add(other_stats()[user], rev, n); 145 else if (lt==LineTypeParser::copyright) 146 add(copyright_stats()[user], rev, n); 126 147 } 127 148 128 129 void Stats::add(std::vector<unsigned int>& vec, unsigned int rev, bool x, 130 unsigned int n) 149 void Stats::add(SumVector& vec, svn_revnum_t rev, unsigned int n) 131 150 { 132 if (vec.size() < rev+1){ 133 vec.reserve(rev+1); 134 vec.resize(rev); 135 assert(vec.size()+1<vec.max_size()); 136 if (x) { 137 vec.push_back(n); 138 } 139 else { 140 vec.push_back(0); 141 } 142 } 143 else if (x) 144 vec[rev]+=n; 145 } 151 vec.set(rev, vec[rev] + n); 152 } 153 */ 146 154 147 155 … … 167 175 void Stats::calc_all(void) 168 176 { 169 std::vector<unsigned int> init(revision()+1); 177 // FIXME: we should use operator+= 178 SumVector init; 170 179 for (int lt=0; lt <= 4; ++lt) { 171 180 stats_[lt]["all"].clear(); … … 173 182 std::accumulate(stats_[lt].begin(), 174 183 stats_[lt].end(), init, 175 PairValuePlus<std::string, unsigned int>());176 } 177 VectorPlus<unsigned int> vp; 184 PairValuePlus<std::string, SumVector>()); 185 } 186 178 187 comment_or_copy_stats()["all"] = 179 vp(comment_stats()["all"], copyright_stats()["all"]); 180 181 total_stats()["all"] = 182 vp(vp(code_stats()["all"], comment_or_copy_stats()["all"]), 183 other_stats()["all"]); 188 comment_stats()["all"] + copyright_stats()["all"]; 189 190 total_stats()["all"] = code_stats()["all"] + 191 comment_or_copy_stats()["all"] + other_stats()["all"]; 184 192 } 185 193 … … 189 197 for (std::set<std::string>::const_iterator iter(authors().begin()); 190 198 iter!=authors().end(); ++iter) { 191 std::vector<unsigned int>& code = code_stats()[*iter]; 192 std::vector<unsigned int>& comments = comment_stats()[*iter]; 193 std::vector<unsigned int>& other = other_stats()[*iter]; 194 std::vector<unsigned int>& copy = copyright_stats()[*iter]; 195 196 VectorPlus<unsigned int> vp; 197 total_stats()[*iter] = vp(vp(vp(code, comments),other),copy); 199 // FIXME: we should uer operator+= 200 const SumVector& code = code_stats()[*iter]; 201 const SumVector& comments = comment_stats()[*iter]; 202 const SumVector& other = other_stats()[*iter]; 203 const SumVector& copy = copyright_stats()[*iter]; 204 205 total_stats()[*iter] = code + comments + other + copy; 206 assert(total_stats()[*iter][100] == 207 code[100]+comments[100]+other[100]+copy[100]); 198 208 } 199 209 … … 205 215 for (std::set<std::string>::const_iterator iter(authors().begin()); 206 216 iter!=authors().end(); ++iter) { 207 std::vector<unsigned int>& comments = comment_stats()[*iter];208 std::vector<unsigned int>& copy = copyright_stats()[*iter];209 210 VectorPlus<unsigned int> vp;211 comment_or_copy_stats()[*iter] = vp(comments, copy);217 const SumVector& comments = comment_stats()[*iter]; 218 const SumVector& copy = copyright_stats()[*iter]; 219 220 // FIXME: we should use operator+= 221 comment_or_copy_stats()[*iter] = comments + copy; 212 222 } 213 223 … … 242 252 243 253 244 const std::vector<unsigned int>& Stats::get_vector(const Author2Vector& m,245 std::stringuser) const254 const SumVector& Stats::get_vector(const Author2Vector& m, 255 const std::string& user) const 246 256 { 247 257 A2VConstIter iter(m.find(std::string(user))); … … 269 279 std::string name; 270 280 std::getline(is, name); 271 std::vector<unsigned int>& vec=m[name];281 SparseVector vec; 272 282 std::string line; 273 283 std::getline(is, line); … … 281 291 if (!count) 282 292 break; 283 vec. resize(std::max(vec.size(),static_cast<size_t>(rev+1)));284 vec[rev]=count;285 }286 accumulate(vec );293 vec.set(rev, count); 294 } 295 SumVector& sumvec = m[name]; 296 accumulate(vec, sumvec); 287 297 } 288 298 } … … 368 378 // keys are equivalent 369 379 else { 370 VectorPlus<Author2Vector::mapped_type::value_type> vp; 371 first2->second = vp(first1->second, first2->second); 380 first2->second = first1->second + first2->second; 372 381 ++first1; 373 382 ++first2; … … 377 386 378 387 379 unsigned int Stats::max_element(const std::vector<unsigned int>& vec) const 380 { 381 return *std::max_element(vec.begin(), vec.end()); 388 unsigned int Stats::max_element(const SumVector& vec) const 389 { 390 return std::max_element(vec.begin(), vec.end(), 391 pair_value_compare<const svn_revnum_t, unsigned int>())->second; 382 392 } 383 393 … … 388 398 for (size_t i=0; i<stats_.size(); ++i) 389 399 for (A2VIter iter=stats_[i].begin(); iter!=stats_[i].end(); ++iter) { 390 iter->second.resize(rev,0);391 iter->second.resize(revision(),0);400 //iter->second.resize(rev,0); 401 //iter->second.resize(revision(),0); 392 402 } 393 403 do_parse(path, rev); … … 395 405 calc_total(); 396 406 calc_all(); 407 397 408 assert(total_stats().size()); 398 409 assert(code_stats().size()); … … 422 433 const std::string& format) const 423 434 { 424 assert(total_stats().size());425 435 Graph gp(filename+"."+format, format); 426 436 const Author2Vector* stat=NULL; … … 436 446 assert(stat->size()); 437 447 assert(stat->find("all")!=stat->end()); 438 std::vector<unsigned int> total=get_vector(*stat, "all"); 448 // FIXME: try keep a const& to avoid copying 449 SumVector total=get_vector(*stat, "all"); 450 total.resize(revision()); 439 451 double yrange_max=1.03 * max_element(total) +1.0; 440 452 gp.ymax(yrange_max); 441 453 442 typedef std::vector<std::pair<std::string, std::vector<unsigned int>> > vec_type;454 typedef std::vector<std::pair<std::string, SumVector> > vec_type; 443 455 vec_type author_cont; 444 456 author_cont.reserve(stat->size()); … … 446 458 i != authors_.end(); ++i) { 447 459 assert(stat->find(*i)!=stat->end()); 448 const std::vector<unsigned int>& vec = get_vector(*stat,*i); 460 // FIXME: avoid this copying? 461 SumVector vec = get_vector(*stat,*i); 462 vec.resize(revision()); 449 463 if (max_element(vec)) { 450 464 author_cont.push_back(std::make_pair(*i,vec)); … … 452 466 } 453 467 454 LessReversed< std::vector<unsigned int>> lr;455 PairSecondCompare<std::string, std::vector<unsigned int>,456 LessReversed<std::vector<unsigned int> > >compare(lr);468 LessReversed<SumVector> lr; 469 PairSecondCompare<std::string, SumVector, LessReversed<SumVector> > 470 compare(lr); 457 471 std::sort(author_cont.begin(), author_cont.end(), compare); 458 472 … … 466 480 vec_type::iterator j(i); 467 481 i+=authskip; 468 std::vector<unsigned int> init(revision()+1);469 std::vector<unsigned int>others =470 std::accumulate(j, i, init, PairValuePlus<std::string, unsigned int>());482 SumVector init; 483 SumVector others = 484 std::accumulate(j, i, init, PairValuePlus<std::string, SumVector>()); 471 485 unsigned char r, g, b; 472 486 std::string label("others"); … … 504 518 { 505 519 Graph gp(filename+"."+format, format); 506 std::vector<unsigned int> total = get_vector(total_stats(), "all"); 520 // FIXME: why not const& 521 SumVector total = get_vector(total_stats(), "all"); 507 522 double yrange_max=1.03*total.back()+1; 508 523 gp.ymax(yrange_max); 509 524 510 std::vector<unsigned int> x(get_vector(code_stats(), "all")); 525 // FIXME: why not const& 526 SumVector x(get_vector(code_stats(), "all")); 511 527 gp.current_color(255,255,0); 512 528 gp.plot(x, "code", x.back()); … … 549 565 for (A2VConstIter i(m.begin()); i!=m.end(); ++i){ 550 566 os << i->first << "\n"; 551 assert(i->second.size());552 567 if (i->second[0]) 553 568 os << 0 << " " << i->second[0] << " "; 569 // FIXME: ise Vector::iterator 554 570 for (size_t j=1; j<i->second.size(); ++j) { 555 571 // only print if stats changes in this rev … … 566 582 for (size_t i=0; i<stats_.size(); ++i){ 567 583 stats_[i].clear(); 568 std::vector<unsigned int>& tmp = stats_[i]["all"]; 569 std::fill(tmp.begin(), tmp.end(), 0); 570 tmp.resize(revision_+1); 584 stats_[i]["all"].resize(revision()+1); 571 585 } 572 586 authors_.clear(); 587 } 588 589 590 void Stats::resize(svn_revnum_t rev) 591 { 592 // set size on vectors 593 for (size_t i=0; i<stats_.size(); ++i) { 594 for (A2VIter iter=stats_[i].begin(); iter!=stats_[i].end(); ++iter) { 595 iter->second.resize(rev); 596 } 597 } 598 } 599 600 601 svn_revnum_t Stats::revision(void) const 602 { 603 return revision_; 573 604 } 574 605 … … 599 630 throw std::runtime_error(msg.str()); 600 631 } 601 assert(rev < static_cast<svn_revnum_t>(i->second.size())); 632 assert(rev <= revision()); 633 // assert(rev < static_cast<svn_revnum_t>(i->second.size())); 602 634 return i->second[rev]; 603 635 } -
trunk/lib/Stats.h
r1124 r1194 26 26 27 27 #include "LineTypeParser.h" 28 #include "Vector.h" 28 29 29 30 #include <subversion-1/svn_types.h> … … 57 58 /// @brief adding \a n line(s) to \a user from \a revision to the stats 58 59 /// 59 void add(const std::string& user, const unsigned int&revision,60 const LineTypeParser::line_type&, unsigned int n=1);60 // void add(const std::string& user, svn_revnum_t revision, 61 // LineTypeParser::line_type, unsigned int n=1); 61 62 62 63 /// … … 127 128 void reset(void); 128 129 130 /** 131 set vectors in stats_ to size \a rev 132 */ 133 void resize(svn_revnum_t rev); 134 129 135 /// 130 136 /// \return latest revision for whole project 131 137 /// 132 svn_revnum_t revision(void) const { return revision_; }138 svn_revnum_t revision(void) const; 133 139 134 140 /** … … 146 152 147 153 protected: 148 typedef std::map<std::string, std::vector<unsigned int>> Author2Vector;154 typedef std::map<std::string, SumVector> Author2Vector; 149 155 typedef Author2Vector::iterator A2VIter; 150 156 typedef Author2Vector::const_iterator A2VConstIter; 157 158 std::vector<Author2Vector> stats_; // from linetype to a2v 159 160 /** 161 */ 162 void add(const std::vector<std::map<std::string, SparseVector> >& data); 151 163 152 164 /** … … 155 167 \see accumulate 156 168 */ 157 void accumulate_stats(svn_revnum_t rev=1);169 // void accumulate_stats(svn_revnum_t rev=1); 158 170 void add_author(std::string); 159 171 void add_authors(std::set<std::string>::const_iterator, … … 197 209 std::set<std::string> authors_; 198 210 199 const std::vector<unsigned int>& get_vector(const Author2Vector&,200 std::stringuser) const;211 const SumVector& get_vector(const Author2Vector&, 212 const std::string& user) const; 201 213 private: 202 214 /// one liner used in cache file to validate that cache file was … … 204 216 std::string config_code_; 205 217 218 void add(SumVector& vec, svn_revnum_t rev, unsigned int n); 206 219 /** 207 220 \a vec is resized to revision(). … … 211 224 et cetera 212 225 */ 213 void accumulate(std::vector<unsigned int>& vec,214 215 void add(std::vector<unsigned int>& vec, unsigned int rev, bool x,216 226 // void accumulate(std::vector<unsigned int>& vec, 227 // svn_revnum_t rev=1) const; 228 // void add(std::vector<unsigned int>& vec, unsigned int rev, bool x, 229 // unsigned int n); 217 230 218 231 /** … … 231 244 called from plot(2) 232 245 */ 246 // FIXME: why should Stats know about plotting? 233 247 void plot(const std::string& basename, const std::string& linetype, 234 248 const std::string& format) const; … … 237 251 called from plot_summary(1) 238 252 */ 253 // FIXME: why should Stats know about plotting? 239 254 void plot_summary(const std::string& basename, 240 255 const std::string& format) const; … … 258 273 \return the largest largest element in \a v. 259 274 */ 260 virtual unsigned int max_element(const std::vector<unsigned int>& v) const;275 virtual unsigned int max_element(const SumVector& v) const; 261 276 262 277 void print(std::ostream& os, const Author2Vector& m) const; … … 264 279 svn_revnum_t revision_; // Should be the latest revision for whole project 265 280 svn_revnum_t last_changed_rev_; // Should be the latest revision for file 266 267 std::vector<Author2Vector> stats_; // from linetype to a2v268 281 269 282 // using compiler generated copy constructor -
trunk/lib/Vector.h
r1187 r1194 23 23 */ 24 24 25 #include <iostream> 26 25 27 #include <subversion-1/svn_types.h> 26 28 29 #include <algorithm> 30 #include <cassert> 27 31 #include <map> 28 32 … … 39 43 // iterator to underlying container, used in begin() and end() 40 44 typedef typename Map::const_iterator const_iterator; 45 // iterator to underlying container, used in begin() and end() 46 typedef typename Map::const_reverse_iterator const_reverse_iterator; 41 47 42 48 /** 43 49 \brief default constructor 44 50 */ 45 Vector(void) {} 51 Vector(void) 52 : size_(0) 53 {} 54 55 /** 56 \note Vector cannot be empty 57 58 \return last element 59 */ 60 T back(void) const 61 { 62 // FIXME: avoid logN lookup time 63 assert(size()>0); 64 return (*this)[size()-1]; 65 } 46 66 47 67 /** … … 57 77 \brief make container empty 58 78 */ 59 void clear(void) { map_.clear(); } 79 void clear(void) 80 { 81 map_.clear(); 82 size_ = 0; 83 } 84 85 /** 86 \return true if Vector is empty 87 */ 88 bool empty(void) const 89 { return map_.empty(); } 60 90 61 91 /* … … 65 95 66 96 /** 97 same as begin() but reverse iterator 98 */ 99 const_reverse_iterator rbegin(void) const { return map_.rbegin(); } 100 101 /** 102 same as end() but reverse iterator 103 */ 104 const_reverse_iterator rend(void) const { return map_.rend(); } 105 106 /* 107 set size to \a size 108 */ 109 void resize(svn_revnum_t size) 110 { 111 size_ = size; 112 } 113 114 /** 67 115 works as vec[revision] = count 68 116 */ … … 71 119 // FIXME: we should let policy collaps map, if possible 72 120 map_[revision] = count; 121 size_ = std::max(revision+1, size_); 73 122 } 74 123 … … 89 138 90 139 /** 91 \return 0 if Vector is empty; otherwise the largest_rev + 1 92 */ 93 size_t size(void) const 94 { 95 if (map_.empty()) 96 return 0; 97 return map_.rbegin()->first + 1; 140 \brief add \a other to this 141 */ 142 Vector& operator+=(const Vector& other) 143 { 144 Vector result; 145 typename Map::iterator first1 = map_.begin(); 146 typename Map::iterator last1 = map_.end(); 147 const_iterator first2 = other.begin(); 148 const_iterator last2 = other.end(); 149 while (first1!=last1 || first2!=last2) { 150 svn_revnum_t rev = 0; 151 if (first1==last1) { 152 rev = first2->first; 153 ++first2; 154 } 155 else if (first2==last2) { 156 rev = first1->first; 157 ++first1; 158 } 159 else if (first1->first < first2->first) { 160 rev = first1->first; 161 ++first1; 162 } 163 else if (first1->first == first2->first) { 164 rev = first1->first; 165 ++first1; 166 ++first2; 167 } 168 else if (first1->first > first2->first) { 169 rev = first2->first; 170 ++first2; 171 } 172 result.set(rev, (*this)[rev] + other[rev]); 173 } 174 // assign result map to this 175 std::swap(map_, result.map_); 176 resize(std::max(size_, other.size())); 177 } 178 179 /** 180 \return size of vector 181 */ 182 svn_revnum_t size(void) const 183 { 184 return size_; 98 185 } 99 186 … … 101 188 Map map_; 102 189 Policy policy_; 190 svn_revnum_t size_; 103 191 104 192 // using compiler generated copy constructor … … 106 194 // Vector& operator=(const Vector&); 107 195 }; 196 197 template<typename T, class Policy> 198 Vector<T, Policy> operator+(const Vector<T, Policy>& lhs, 199 const Vector<T, Policy>& rhs) 200 { 201 Vector<T, Policy> result(lhs); 202 result+=rhs; 203 assert(result.size()>=lhs.size()); 204 assert(result.size()>=rhs.size()); 205 return result; 206 } 207 108 208 109 209 template<typename T> … … 147 247 result[i] = result[i-1] + vec[i]; 148 248 */ 149 void accumulate(const SparseVector& vec, SumVector& result) 150 { 151 result.clear(); 152 unsigned int value = 0; 153 for (SumVector::const_iterator iter = vec.begin(); iter!=vec.end();++iter) { 154 value += iter->second; 155 result.set(iter->first, value); 156 } 157 } 249 void accumulate(const SparseVector& vec, SumVector& result); 158 250 159 251 }} // end of namespace svndigest and namespace theplu -
trunk/test/graph.cc
r1189 r1194 75 75 graph.ymax(10); 76 76 graph.current_color(255, 0, 0); 77 /*78 77 SumVector data; 79 78 data.set(99,1); 80 */ 81 std::vector<unsigned int> data(100,1); 79 // std::vector<unsigned int> data(100,1); 82 80 graph.plot(data, "label", 1); 83 81 } -
trunk/test/vector.cc
r1187 r1194 45 45 46 46 template<class T> 47 void run_test(T vec, test::Suite& )47 void run_test(T vec, test::Suite& suite) 48 48 { 49 49 vec.begin(); … … 52 52 vec[0]; 53 53 vec.set(0, 0); 54 55 vec.set(5,10); 56 T vec2(vec); 57 vec2.set(7,11); 58 T vec3; 59 vec3 = vec2; 60 suite.out() << "testing assignment\n"; 61 if (vec3.size()!=vec2.size()) { 62 suite.add(false); 63 suite.out() << "incorrect size: " << vec3.size() << " expected: " 64 << vec2.size() << "\n"; 65 } 66 67 suite.out() << "testing operator+\n"; 68 vec3 = vec + vec2; 69 if (vec3.size()!=8) { 70 suite.add(false); 71 suite.out() << "incorrect size: " << vec3.size() << " expected: " 72 << 8 << "\n"; 73 } 74 for (size_t i=0; i<8; ++i) 75 if (!suite.add(vec3[5]==vec[5]+vec2[5])) 76 suite.out() << "operator+ failed: result: " << vec3[i] 77 << " expected: " << vec[i] + vec2[i] << "\n"; 54 78 } 55 79
Note: See TracChangeset
for help on using the changeset viewer.