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 #include <sys/types.h>
7 
8 namespace pat {
9 
10  template <typename Comparator, typename Arbitrator>
12 
13  public:
14 
17  GenericDuplicateRemover(const Comparator &comp, const Arbitrator &arbiter) : comparator_(comp), arbiter_(arbiter) {}
18 
20 
26  template <typename Collection>
27  std::auto_ptr< std::vector<size_t> >
28  duplicates(const Collection &items) const ;
29 
30  private:
32  Arbitrator arbiter_;
33 
34  }; // class
35 }
36 
37 template<typename Comparator, typename Arbitrator>
38 template<typename Collection>
39 std::auto_ptr< std::vector<size_t> >
41 {
42  size_t size = items.size();
43 
44  std::vector<bool> bad(size, false);
45 
46  for (size_t ie = 0; ie < size; ++ie) {
47  if (bad[ie]) continue; // if already marked bad
48 
49  for (size_t je = ie+1; je < size; ++je) {
50 
51  if (bad[je]) continue; // if already marked bad
52 
53  if ( comparator_(items[ie], items[je]) ) {
54  int toRemove = arbiter_(items[ie], items[je]) ? je : ie;
55  bad[toRemove] = true;
56  }
57  }
58  }
59 
60  std::auto_ptr< std::vector<size_t> > ret(new std::vector<size_t>());
61 
62  for (size_t i = 0; i < size; ++i) {
63  if (bad[i]) ret->push_back(i);
64  }
65 
66  return ret;
67 }
68 
69 
70 #endif
int i
Definition: DBlmapReader.cc:9
tuple ret
prodAgent to be discontinued
std::auto_ptr< std::vector< size_t > > duplicates(const Collection &items) const
GenericDuplicateRemover(const Comparator &comp, const Arbitrator &arbiter)
GenericDuplicateRemover(const Comparator &comp)
tuple size
Write out results.