CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
GenericDuplicateRemover.h
Go to the documentation of this file.
1 #ifndef PhysicsTools_PatUtils_GenericDuplicateRemover_h
2 #define PhysicsTools_PatUtils_GenericDuplicateRemover_h
3 
4 #include <memory>
5 #include <vector>
6 
7 namespace pat {
8 
9  template <typename Comparator, typename Arbitrator>
11 
12  public:
13 
16  GenericDuplicateRemover(const Comparator &comp, const Arbitrator &arbiter) : comparator_(comp), arbiter_(arbiter) {}
17 
19 
25  template <typename Collection>
26  std::auto_ptr< std::vector<size_t> >
27  duplicates(const Collection &items) const ;
28 
29  private:
31  Arbitrator arbiter_;
32 
33  }; // class
34 }
35 
36 template<typename Comparator, typename Arbitrator>
37 template<typename Collection>
38 std::auto_ptr< std::vector<size_t> >
40 {
41  size_t size = items.size();
42 
43  std::vector<bool> bad(size, false);
44 
45  for (size_t ie = 0; ie < size; ++ie) {
46  if (bad[ie]) continue; // if already marked bad
47 
48  for (size_t je = ie+1; je < size; ++je) {
49 
50  if (bad[je]) continue; // if already marked bad
51 
52  if ( comparator_(items[ie], items[je]) ) {
53  int toRemove = arbiter_(items[ie], items[je]) ? je : ie;
54  bad[toRemove] = true;
55  }
56  }
57  }
58 
59  std::auto_ptr< std::vector<size_t> > ret(new std::vector<size_t>());
60 
61  for (size_t i = 0; i < size; ++i) {
62  if (bad[i]) ret->push_back(i);
63  }
64 
65  return ret;
66 }
67 
68 
69 #endif
int i
Definition: DBlmapReader.cc:9
std::auto_ptr< std::vector< size_t > > duplicates(const Collection &items) const
int bad(Items const &cont)
GenericDuplicateRemover(const Comparator &comp, const Arbitrator &arbiter)
GenericDuplicateRemover(const Comparator &comp)
tuple size
Write out results.