CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
edm::IndexSet Class Reference

#include <IndexSet.h>

Public Member Functions

void clear ()
 Clear the set. More...
 
bool empty () const
 Check if the set is empty. More...
 
bool has (unsigned int index) const
 Check if an element (=index) is in the set. More...
 
 IndexSet ()
 Construct empty set. More...
 
void insert (unsigned int index)
 Insert an element (=index) to the set. More...
 
void reserve (unsigned int size)
 Reserve memory for the set. More...
 
unsigned int size () const
 Number of elements in the set. More...
 

Private Attributes

std::vector< bool > content_
 
unsigned int numTrueElements_
 Each possible element of the set corresponds an index in this vector. The value of an element tells if that index exists in the set (true) or not (false). More...
 

Detailed Description

A simple class representing a set of indices to another container for fast insert and search.

This class can be useful if one needs to record the indices of objects that form a subset of a container (e.g. passing some selection), and then repeatedly check if an object of a given index belongs to that subset. As the elements are assumed to be indices, the set can be implemented as a vector<bool> such that each possible element corresponds an index in the vector. Then the insert and search are (almost) array access operations.

From the set opreations, only insertion, search, and clear are supported for now. More can be added if needed.

Definition at line 22 of file IndexSet.h.

Constructor & Destructor Documentation

edm::IndexSet::IndexSet ( )
inline

Construct empty set.

Definition at line 25 of file IndexSet.h.

25 : numTrueElements_(0) {}
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

Member Function Documentation

void edm::IndexSet::clear ( void  )
inline

Clear the set.

Definition at line 41 of file IndexSet.h.

References begin, content_, end, lumiContext::fill, and numTrueElements_.

41  {
42  std::fill(begin(content_), end(content_), false);
43  numTrueElements_ = 0;
44  }
std::vector< bool > content_
Definition: IndexSet.h:58
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
#define end
Definition: vmac.h:39
#define begin
Definition: vmac.h:32
bool edm::IndexSet::empty ( void  ) const
inline

Check if the set is empty.

Definition at line 28 of file IndexSet.h.

References numTrueElements_.

28 { return numTrueElements_ == 0; }
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 edm::IndexSet::has ( unsigned int  index) const
inline

Check if an element (=index) is in the set.

Definition at line 54 of file IndexSet.h.

References content_.

Referenced by QuickTrackAssociatorByHitsImpl::associateTrack(), and MultiTrackValidator::bookHistograms().

54 { return index < content_.size() && content_[index]; }
std::vector< bool > content_
Definition: IndexSet.h:58
void edm::IndexSet::insert ( unsigned int  index)
inline

Insert an element (=index) to the set.

Definition at line 47 of file IndexSet.h.

References content_, numTrueElements_, and reserve().

Referenced by MultiTrackValidator::bookHistograms().

47  {
48  reserve(index + 1);
49  numTrueElements_ += !content_[index]; // count increases if value was false
50  content_[index] = true;
51  }
std::vector< bool > content_
Definition: IndexSet.h:58
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
void reserve(unsigned int size)
Reserve memory for the set.
Definition: IndexSet.h:34
void edm::IndexSet::reserve ( unsigned int  size)
inline

Reserve memory for the set.

Definition at line 34 of file IndexSet.h.

References content_.

Referenced by associationMapFilterValues(), MultiTrackValidator::bookHistograms(), and insert().

34  {
35  if (size >= content_.size()) {
36  content_.resize(size, false);
37  }
38  }
unsigned int size() const
Number of elements in the set.
Definition: IndexSet.h:31
std::vector< bool > content_
Definition: IndexSet.h:58
unsigned int edm::IndexSet::size ( void  ) const
inline

Number of elements in the set.

Definition at line 31 of file IndexSet.h.

References numTrueElements_.

Referenced by ntupleDataFormat._Collection::__iter__(), and ntupleDataFormat._Collection::__len__().

31 { return 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

Member Data Documentation

std::vector<bool> edm::IndexSet::content_
private

Definition at line 58 of file IndexSet.h.

Referenced by clear(), has(), insert(), and reserve().

unsigned int edm::IndexSet::numTrueElements_
private

Each possible element of the set corresponds an index in this vector. The value of an element tells if that index exists in the set (true) or not (false).

Definition at line 59 of file IndexSet.h.

Referenced by clear(), empty(), insert(), and size().