CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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  public:
15  GenericDuplicateRemover(const Comparator &comp, const Arbitrator &arbiter) : comparator_(comp), arbiter_(arbiter) {}
16 
18 
24  template <typename Collection>
25  std::unique_ptr<std::vector<size_t>> duplicates(const Collection &items) const;
26 
27  private:
29  Arbitrator arbiter_;
30 
31  }; // class
32 } // namespace pat
33 
34 template <typename Comparator, typename Arbitrator>
35 template <typename Collection>
37  const Collection &items) const {
38  size_t size = items.size();
39 
40  std::vector<bool> bad(size, false);
41 
42  for (size_t ie = 0; ie < size; ++ie) {
43  if (bad[ie])
44  continue; // if already marked bad
45 
46  for (size_t je = ie + 1; je < size; ++je) {
47  if (bad[je])
48  continue; // if already marked bad
49 
50  if (comparator_(items[ie], items[je])) {
51  int toRemove = arbiter_(items[ie], items[je]) ? je : ie;
52  bad[toRemove] = true;
53  }
54  }
55  }
56 
57  auto ret = std::make_unique<std::vector<size_t>>();
58 
59  for (size_t i = 0; i < size; ++i) {
60  if (bad[i])
61  ret->push_back(i);
62  }
63 
64  return ret;
65 }
66 
67 #endif
tuple ret
prodAgent to be discontinued
GenericDuplicateRemover(const Comparator &comp, const Arbitrator &arbiter)
std::unique_ptr< std::vector< size_t > > duplicates(const Collection &items) const
GenericDuplicateRemover(const Comparator &comp)
tuple size
Write out results.