Jpp test-rotations-old
the software that should make you happy
Loading...
Searching...
No Matches
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.
 
 JCombinatorics (const int numberOfIndices)
 Constructor.
 
const JCombinatoricsgetCombinatorics () const
 Get combinatorics.
 
void configure (const int numberOfIndices)
 Configure.
 
size_t getNumberOfIndices () const
 Get number of indices.
 
size_t getNumberOfPairs () const
 Get number of pairs.
 
int getIndex (const int first, const int second) const
 Get index of pair of indices.
 
int getIndex (const pair_type &pair) const
 Get index of pair.
 
const pair_typegetPair (const int index) const
 Get pair of indices for given index.
 
template<class JComparator_t >
void sort (JComparator_t comparator)
 Sort address pairs.
 

Static Public Member Functions

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

Protected Attributes

std::vector< pair_typezbuf1D
 
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

◆ JCombinatorics() [1/2]

JTOOLS::JCombinatorics::JCombinatorics ( )
inline

Default constructor.

Definition at line 69 of file JCombinatorics.hh.

70 {}

◆ JCombinatorics() [2/2]

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

◆ getCombinatorics()

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

Get combinatorics.

Returns
combinatorics

Definition at line 89 of file JCombinatorics.hh.

90 {
91 return *this;
92 }

◆ configure()

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 }
std::vector< pair_type > zbuf1D
std::vector< std::vector< int > > zbuf2D
JCombinatorics::pair_type pair_type
int j
Definition JPolint.hh:801

◆ getNumberOfIndices()

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 }

◆ getNumberOfPairs()

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 }

◆ getIndex() [1/2]

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 }

◆ getIndex() [2/2]

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.

◆ getPair()

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 }

◆ sort()

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 }

◆ getSign() [1/2]

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 }

◆ getSign() [2/2]

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

◆ zbuf1D

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

Definition at line 234 of file JCombinatorics.hh.

◆ zbuf2D

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: