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 23 of file IndexSet.h.

Constructor & Destructor Documentation

edm::IndexSet::IndexSet ( )
inline

Construct empty set.

Definition at line 26 of file IndexSet.h.

26 : 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:61

Member Function Documentation

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

Clear the set.

Definition at line 42 of file IndexSet.h.

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

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

Check if the set is empty.

Definition at line 29 of file IndexSet.h.

References numTrueElements_.

29 { 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:61
bool edm::IndexSet::has ( unsigned int  index) const
inline

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

Definition at line 55 of file IndexSet.h.

References content_, and diffTreeTool::index.

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

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

Insert an element (=index) to the set.

Definition at line 48 of file IndexSet.h.

References content_, diffTreeTool::index, numTrueElements_, and reserve().

Referenced by MultiTrackValidator::bookHistograms().

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

Reserve memory for the set.

Definition at line 35 of file IndexSet.h.

References content_.

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

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

Number of elements in the set.

Definition at line 32 of file IndexSet.h.

References numTrueElements_.

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

32 { 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:61

Member Data Documentation

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

Definition at line 60 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 61 of file IndexSet.h.

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