CMS 3D CMS Logo

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 
7 namespace edm {
23  class IndexSet {
24  public:
27 
29  bool empty() const { return numTrueElements_ == 0; }
30 
32  unsigned int size() const { return numTrueElements_; }
33 
35  void reserve(unsigned int size) {
36  if(size >= content_.size()) {
37  content_.resize(size, false);
38  }
39  }
40 
42  void clear() {
43  std::fill(begin(content_), end(content_), false);
44  numTrueElements_ = 0;
45  }
46 
48  void insert(unsigned int index) {
49  reserve(index+1);
50  numTrueElements_ += !content_[index]; // count increases if value was false
51  content_[index] = true;
52  }
53 
55  bool has(unsigned int index) const {
56  return index < content_.size() && content_[index];
57  }
58 
59  private:
60  std::vector<bool> content_;
61  unsigned int numTrueElements_;
62  };
63 }
64 
65 #endif
void clear()
Clear the set.
Definition: IndexSet.h:42
unsigned int size() const
Number of elements in the set.
Definition: IndexSet.h:32
std::vector< bool > content_
Definition: IndexSet.h:60
bool has(unsigned int index) const
Check if an element (=index) is in the set.
Definition: IndexSet.h:55
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:61
#define end
Definition: vmac.h:37
bool empty() const
Check if the set is empty.
Definition: IndexSet.h:29
#define begin
Definition: vmac.h:30
HLT enums.
IndexSet()
Construct empty set.
Definition: IndexSet.h:26
void insert(unsigned int index)
Insert an element (=index) to the set.
Definition: IndexSet.h:48
void reserve(unsigned int size)
Reserve memory for the set.
Definition: IndexSet.h:35