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

◆ IndexSet()

edm::IndexSet::IndexSet ( )
inline

Construct empty set.

Definition at line 25 of file IndexSet.h.

25 : numTrueElements_(0) {}

Member Function Documentation

◆ clear()

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

Clear the set.

Definition at line 41 of file IndexSet.h.

41  {
42  std::fill(begin(content_), end(content_), false);
43  numTrueElements_ = 0;
44  }

References content_, mps_fire::end, ntuplemaker::fill, and numTrueElements_.

◆ empty()

bool edm::IndexSet::empty ( void  ) const
inline

Check if the set is empty.

Definition at line 28 of file IndexSet.h.

28 { return numTrueElements_ == 0; }

References numTrueElements_.

◆ has()

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.

54 { return index < content_.size() && content_[index]; }

References content_.

Referenced by QuickTrackAssociatorByHitsImpl::associateTrack().

◆ insert()

void edm::IndexSet::insert ( unsigned int  index)
inline

Insert an element (=index) to the set.

Definition at line 47 of file IndexSet.h.

47  {
48  reserve(index + 1);
49  numTrueElements_ += !content_[index]; // count increases if value was false
50  content_[index] = true;
51  }

References content_, numTrueElements_, and reserve().

◆ reserve()

void edm::IndexSet::reserve ( unsigned int  size)
inline

Reserve memory for the set.

Definition at line 34 of file IndexSet.h.

34  {
35  if (size >= content_.size()) {
36  content_.resize(size, false);
37  }
38  }

References content_, and size().

Referenced by associationMapFilterValues(), and insert().

◆ size()

unsigned int edm::IndexSet::size ( void  ) const
inline

Number of elements in the set.

Definition at line 31 of file IndexSet.h.

31 { return numTrueElements_; }

References numTrueElements_.

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

Member Data Documentation

◆ content_

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

Definition at line 58 of file IndexSet.h.

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

◆ numTrueElements_

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().

edm::IndexSet::content_
std::vector< bool > content_
Definition: IndexSet.h:58
edm::IndexSet::reserve
void reserve(unsigned int size)
Reserve memory for the set.
Definition: IndexSet.h:34
mps_fire.end
end
Definition: mps_fire.py:242
ntuplemaker.fill
fill
Definition: ntuplemaker.py:304
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