Last change
on this file since 14 was
14,
checked in by Peter Johansson, 17 years ago
|
adding Stats class and removed pointer from node to its mother(dir), which enforced some changes here and there
|
File size:
1.5 KB
|
Line | |
---|
1 | //$Id$ |
---|
2 | |
---|
3 | #include "Stats.h" |
---|
4 | #include "utility.h" |
---|
5 | |
---|
6 | #include <map> |
---|
7 | #include <numeric> |
---|
8 | #include <string> |
---|
9 | #include <vector> |
---|
10 | |
---|
11 | namespace theplu{ |
---|
12 | namespace svnstat{ |
---|
13 | |
---|
14 | Stats::Stats() |
---|
15 | { |
---|
16 | } |
---|
17 | |
---|
18 | |
---|
19 | std::vector<u_int> Stats::accumulated(void) const |
---|
20 | { |
---|
21 | std::vector<u_int> sum; |
---|
22 | if (map_.empty()) |
---|
23 | return sum; |
---|
24 | |
---|
25 | // sum of all users |
---|
26 | std::accumulate(map_.begin(), map_.end(), sum, |
---|
27 | PairValuePlus<std::string,u_int>()); |
---|
28 | |
---|
29 | // calculate accumulated sum |
---|
30 | std::vector<u_int> accum(sum.size()); |
---|
31 | std::partial_sum(sum.begin(),sum.end(),accum.begin()); |
---|
32 | return accum; |
---|
33 | } |
---|
34 | |
---|
35 | std::vector<u_int> Stats::accumulated(const std::string& user) |
---|
36 | { |
---|
37 | std::vector<u_int> vec=map_[user]; |
---|
38 | if (vec.empty()) |
---|
39 | return vec; |
---|
40 | std::vector<u_int> accum(vec.size()); |
---|
41 | std::partial_sum(vec.begin(),vec.end(),accum.begin()); |
---|
42 | return accum; |
---|
43 | } |
---|
44 | |
---|
45 | void Stats::add(const std::string& user, const u_int& rev) |
---|
46 | { |
---|
47 | std::vector<u_int> vec = map_[user]; |
---|
48 | if (vec.size() < rev+1){ |
---|
49 | u_int i=vec.size(); |
---|
50 | vec.resize(rev+1); |
---|
51 | for (; i<rev; i++) |
---|
52 | vec[i]=0; |
---|
53 | vec[rev]=1; |
---|
54 | } |
---|
55 | else |
---|
56 | vec[rev]++; |
---|
57 | map_[user]=vec; |
---|
58 | |
---|
59 | } |
---|
60 | |
---|
61 | Stats& Stats::operator+=(const Stats& other) |
---|
62 | { |
---|
63 | for (_MapConstIt o_i= other.map_.begin(); o_i != other.map_.end(); ++o_i) |
---|
64 | { |
---|
65 | std::pair<_MapIt,bool> result = map_.insert(*o_i); |
---|
66 | if (!result.second) |
---|
67 | map_[(*(result.first)).first] = |
---|
68 | VectorPlus<u_int>()( (*(result.first)).second, (*o_i).second ); |
---|
69 | |
---|
70 | } |
---|
71 | return *this; |
---|
72 | } |
---|
73 | |
---|
74 | }} // end of namespace svnstat and namespace theplu |
---|
Note: See
TracBrowser
for help on using the repository browser.