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 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
edm::IndexSet::content_
std::vector< bool > content_
Definition: IndexSet.h:58
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::IndexSet::reserve
void reserve(unsigned int size)
Reserve memory for the set.
Definition: IndexSet.h:34
edm::IndexSet::has
bool has(unsigned int index) const
Check if an element (=index) is in the set.
Definition: IndexSet.h:54
mps_fire.end
end
Definition: mps_fire.py:242
ntuplemaker.fill
fill
Definition: ntuplemaker.py:304
edm::IndexSet
Definition: IndexSet.h:22
edm::IndexSet::insert
void insert(unsigned int index)
Insert an element (=index) to the set.
Definition: IndexSet.h:47
edm::IndexSet::IndexSet
IndexSet()
Construct empty set.
Definition: IndexSet.h:25
edm::IndexSet::size
unsigned int size() const
Number of elements in the set.
Definition: IndexSet.h:31
edm::IndexSet::numTrueElements_
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
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
edm::IndexSet::empty
bool empty() const
Check if the set is empty.
Definition: IndexSet.h:28
edm::IndexSet::clear
void clear()
Clear the set.
Definition: IndexSet.h:41