CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
IndexSet.h
Go to the documentation of this file.
1 #ifndef FWCore_Utilities_IndexSet_h
2 #define FWCore_Utilities_IndexSet_h
3 
4 #include <vector>
5 
6 namespace edm {
22  class IndexSet {
23  public:
26 
28  bool empty() const { return numTrueElements_ == 0; }
29 
31  unsigned int size() const { return numTrueElements_; }
32 
34  void reserve(unsigned int size) {
35  if (size >= content_.size()) {
36  content_.resize(size, false);
37  }
38  }
39 
41  void clear() {
42  std::fill(begin(content_), end(content_), false);
43  numTrueElements_ = 0;
44  }
45 
47  void insert(unsigned int index) {
48  reserve(index + 1);
49  numTrueElements_ += !content_[index]; // count increases if value was false
50  content_[index] = true;
51  }
52 
54  bool has(unsigned int index) const { return index < content_.size() && content_[index]; }
55 
56  private:
57  std::vector<bool>
59  unsigned int numTrueElements_;
60  };
61 } // namespace edm
62 
63 #endif
void clear()
Clear the set.
Definition: IndexSet.h:41
unsigned int size() const
Number of elements in the set.
Definition: IndexSet.h:31
std::vector< bool > content_
Definition: IndexSet.h:58
bool has(unsigned int index) const
Check if an element (=index) is in the set.
Definition: IndexSet.h:54
unsigned int numTrueElements_
Each possible element of the set corresponds an index in this vector. The value of an element tells i...
Definition: IndexSet.h:59
bool empty() const
Check if the set is empty.
Definition: IndexSet.h:28
void fill(std::map< std::string, TH1 * > &h, const std::string &s, double x)
string end
Definition: dataset.py:937
IndexSet()
Construct empty set.
Definition: IndexSet.h:25
void insert(unsigned int index)
Insert an element (=index) to the set.
Definition: IndexSet.h:47
void reserve(unsigned int size)
Reserve memory for the set.
Definition: IndexSet.h:34