Jpp  18.3.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Classes | Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
JTOOLS::JCombinatorics Class Reference

Auxiliary class to convert pair of indices to unique index and back. More...

#include <JCombinatorics.hh>

Inheritance diagram for JTOOLS::JCombinatorics:
JCALIBRATE::JCombinatorics_t JCALIBRATE::JModel

Classes

struct  pair_type
 Data structure for a pair of indices. More...
 

Public Member Functions

 JCombinatorics ()
 Default constructor. More...
 
 JCombinatorics (const int numberOfIndices)
 Constructor. More...
 
const JCombinatorics & getCombinatorics () const
 Get combinatorics. More...
 
void configure (const int numberOfIndices)
 Configure. More...
 
size_t getNumberOfIndices () const
 Get number of indices. More...
 
size_t getNumberOfPairs () const
 Get number of pairs. More...
 
int getIndex (const int first, const int second) const
 Get index of pair of indices. More...
 
int getIndex (const pair_type &pair) const
 Get index of pair. More...
 
const pair_type & getPair (const int index) const
 Get pair of indices for given index. More...
 
template<class JComparator_t >
void sort (JComparator_t comparator)
 Sort address pairs. More...
 

Static Public Member Functions

static int getSign (const int first, const int second)
 Sign of pair of indices. More...
 
static int getSign (const pair_type &pair)
 Sign of pair of indices. More...
 

Protected Attributes

std::vector< pair_type > zbuf1D
 
std::vector< std::vector< int > > zbuf2D
 

Detailed Description

Auxiliary class to convert pair of indices to unique index and back.

Definition at line 22 of file JCombinatorics.hh.

Constructor & Destructor Documentation

JTOOLS::JCombinatorics::JCombinatorics ( )
inline

Default constructor.

Definition at line 69 of file JCombinatorics.hh.

70  {}
JTOOLS::JCombinatorics::JCombinatorics ( const int  numberOfIndices)
inline

Constructor.

Parameters
numberOfIndicesnumber of indices

Definition at line 78 of file JCombinatorics.hh.

79  {
80  configure(numberOfIndices);
81  }
void configure(const int numberOfIndices)
Configure.

Member Function Documentation

const JCombinatorics& JTOOLS::JCombinatorics::getCombinatorics ( ) const
inline

Get combinatorics.

Returns
combinatorics

Definition at line 89 of file JCombinatorics.hh.

90  {
91  return *this;
92  }
void JTOOLS::JCombinatorics::configure ( const int  numberOfIndices)
inline

Configure.

Parameters
numberOfIndicesnumber of indices

Definition at line 100 of file JCombinatorics.hh.

101  {
102  zbuf1D.clear();
103 
104  zbuf2D.resize(numberOfIndices);
105 
106  for (int i = 0; i != numberOfIndices; ++i) {
107  zbuf2D[i].resize(numberOfIndices);
108  }
109 
110  for (int i = 0; i != numberOfIndices; ++i) {
111 
112  zbuf2D[i][i] = -1;
113 
114  for (int j = i; ++j != numberOfIndices; ) {
115 
116  zbuf2D[i][j] = zbuf1D.size();
117  zbuf2D[j][i] = zbuf1D.size();
118 
119  zbuf1D.push_back(pair_type(i,j));
120  }
121  }
122  }
JCombinatorics::pair_type pair_type
std::vector< std::vector< int > > zbuf2D
std::vector< pair_type > zbuf1D
int j
Definition: JPolint.hh:792
size_t JTOOLS::JCombinatorics::getNumberOfIndices ( ) const
inline

Get number of indices.

Returns
number of indices

Definition at line 130 of file JCombinatorics.hh.

131  {
132  return zbuf2D.size();
133  }
std::vector< std::vector< int > > zbuf2D
size_t JTOOLS::JCombinatorics::getNumberOfPairs ( ) const
inline

Get number of pairs.

Returns
number of pairs

Definition at line 141 of file JCombinatorics.hh.

142  {
143  return zbuf1D.size();
144  }
std::vector< pair_type > zbuf1D
int JTOOLS::JCombinatorics::getIndex ( const int  first,
const int  second 
) const
inline

Get index of pair of indices.

Parameters
firstfirst address
secondsecond address
Returns
index (-1 if first and second address are equal)

Definition at line 154 of file JCombinatorics.hh.

155  {
156  return zbuf2D[first][second];
157  }
then echo The file $DIR KM3NeT_00000001_00000000 root already please rename or remove it first
std::vector< std::vector< int > > zbuf2D
int JTOOLS::JCombinatorics::getIndex ( const pair_type &  pair) const
inline

Get index of pair.

Parameters
pairpair
Returns
index (-1 if first and second address are equal)

Definition at line 166 of file JCombinatorics.hh.

167  {
168  return getIndex(pair.first, pair.second);
169  }
int getIndex(const int first, const int second) const
Get index of pair of indices.
const pair_type& JTOOLS::JCombinatorics::getPair ( const int  index) const
inline

Get pair of indices for given index.

Parameters
indexindex
Returns
pair of indices

Definition at line 178 of file JCombinatorics.hh.

179  {
180  return zbuf1D[index];
181  }
std::vector< pair_type > zbuf1D
template<class JComparator_t >
void JTOOLS::JCombinatorics::sort ( JComparator_t  comparator)
inline

Sort address pairs.

Parameters
comparatorcomparator for pairs

Definition at line 190 of file JCombinatorics.hh.

191  {
192  std::stable_sort(zbuf1D.begin(), zbuf1D.end(), comparator);
193 
194  for (int i = 0; i != (int) zbuf1D.size(); ++i) {
195 
196  const pair_type pair = zbuf1D[i];
197 
198  zbuf2D[pair.first][pair.second] = i;
199  zbuf2D[pair.second][pair.first] = i;
200  }
201 
202  for (int i = 0; i != (int) zbuf2D.size(); ++i) {
203  zbuf2D[i][i] = -1;
204  }
205  }
JCombinatorics::pair_type pair_type
std::vector< std::vector< int > > zbuf2D
std::vector< pair_type > zbuf1D
static int JTOOLS::JCombinatorics::getSign ( const int  first,
const int  second 
)
inlinestatic

Sign of pair of indices.

Parameters
firstfirst address
secondsecond address
Returns
+1 if second >= first; else -1

Definition at line 215 of file JCombinatorics.hh.

216  {
217  return (second >= first ? +1 : -1);
218  }
then echo The file $DIR KM3NeT_00000001_00000000 root already please rename or remove it first
static int JTOOLS::JCombinatorics::getSign ( const pair_type &  pair)
inlinestatic

Sign of pair of indices.

Parameters
pairpair of indices
Returns
+1 if second >= first; else -1

Definition at line 227 of file JCombinatorics.hh.

228  {
229  return getSign(pair.first, pair.second);
230  }
static int getSign(const int first, const int second)
Sign of pair of indices.

Member Data Documentation

std::vector<pair_type> JTOOLS::JCombinatorics::zbuf1D
protected

Definition at line 234 of file JCombinatorics.hh.

std::vector<std::vector<int> > JTOOLS::JCombinatorics::zbuf2D
protected

Definition at line 235 of file JCombinatorics.hh.


The documentation for this class was generated from the following file: