source: trunk/lib/utility.h @ 18

Last change on this file since 18 was 14, checked in by Peter Johansson, 16 years ago

adding Stats class and removed pointer from node to its mother(dir), which enforced some changes here and there

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 1.4 KB
Line 
1//$Id: utility.h 14 2005-12-30 14:57:47Z peter $
2
3#ifndef _theplu_svnstat_utility_
4#define _theplu_svnstat_utility_
5
6#include <algorithm>
7#include <functional>
8#include <utility>
9#include <vector>
10
11namespace theplu{
12namespace svnstat{
13
14  ///
15  /// Calculating sum of two vectors.
16  ///
17  /// @return resulting vector
18  ///
19  template <class T >
20    struct VectorPlus : 
21  public std::binary_function<std::vector<T>,std::vector<T>,std::vector<T> >
22    {
23      std::vector<T> operator()(const std::vector<T>& u,
24        const std::vector<T>& v) const 
25      {
26  if ( u.size() > v.size() ){
27    std::vector<T> res(u.size());
28    transform(u.begin(), u.end(), v.begin(), res.begin(), std::plus<T>());
29    copy(u.begin()+v.size(), u.end(), res.begin()+v.size());
30    return res;
31  }
32 
33  std::vector<T> res(v.size());
34  transform(v.begin(), v.end(), u.begin(), res.begin(), std::plus<T>());
35  if ( v.size() > u.size() )
36    copy(u.begin()+v.size(), u.end(), res.begin()+v.size());
37  return res;
38      }
39
40    };
41
42  ///
43  /// @return resulting vector
44  ///
45  template <class Key, class T>
46    struct PairValuePlus :
47  public std::binary_function<std::vector<T>,
48    std::pair<const Key, std::vector<T> >, 
49    std::vector<T> >
50    {
51      std::vector<T> operator()(const std::vector<T>& sum, 
52        const std::pair<const Key,std::vector<T> >& p)
53      {
54  return VectorPlus<T>()(sum, p.second);
55      }
56    };
57}}
58
59#endif // end of namespace svnstat end of namespace theplu
Note: See TracBrowser for help on using the repository browser.