SUNphi  1.0
SUNphi::Combinatorial< Int > Class Template Reference

Implements a looper over all combinations of a given kind. More...

#include <Combinatorial.hpp>

Public Member Functions

bool isSlotFree (const Slot &iSlot) const
 Check if the slot is free.
 
bool isSlotFullyOccupied (const Slot &iSlot) const
 Check if the slot is fully occupied.
 
bool canBeMovedRight (const Slot &iSlot) const
 Check if 1 object can be moved from the slot to the right one.
 
void moveRight (const Slot &iSlot)
 Move right one element from the slot.
 
bool canBeMovedLeft (const Slot &iSlot) const
 Check if 1 object can be moved from the slot to the left one.
 
void moveLeft (const Slot &iSlot)
 Move left one element from the slot.
 
bool advance ()
 Go to next combo, returning true if was possible to do it. More...
 
bool rewind ()
 Go to previous combo, returning true if was possible to do it. More...
 
bool rewindOrAdvance (const BACK_FORW &BackForw)
 Go backward or advance depending on the passed parameter.
 
const Vector< Int > & operator() () const
 Const cast to the combinatorial.
 
template<typename... Ts>
decltype(auto) operator() (Ts &&...ts)
 
Vector< Int > getFirst () const
 Get the firt combo.
 
void setToFirst ()
 Set to first combo.
 
void setToLast ()
 Set to last combo.
 
Vector< Int > getLast () const
 Get the last combo.
 
Slot nSlots () const
 Number of slots.
 
Int nMaxObj () const
 Maximal number of objects that can be accommodated.
 
 Combinatorial (const Vector< Int > &nMaxPerSlot, const int nObj, const bool lastOrFirst=false)
 Constructor specifying the maximal number of objects per slot. More...
 

Static Public Member Functions

static bool isPossibleToAccomodate (const Vector< Int > &nMaxPerSlot, const int nObj)
 Check if it is possible to combine the nObj into the slots. More...
 

Private Types

using Slot = typename Vector< Int >::Size
 Type used to enumerate the slots.
 

Private Member Functions

Int assignToSlots (Vector< Int > &res, Int nObjToAss, const Slot &firstSlot, const Slot &pastLastSlot, const Slot &dSlot) const
 
Vector< Int > getFirstOrLast (const FIRST_OR_LAST &firstLast) const
 Get the first or last combo. More...
 

Private Attributes

Vector< Int > nMaxPerSlot
 Maximal number of objects per slot.
 
Int nObj
 Number of objects.
 
Vector< Int > nPerSlot
 Current combination.
 

Detailed Description

template<typename Int = int64_t>
class SUNphi::Combinatorial< Int >

Implements a looper over all combinations of a given kind.

Definition at line 21 of file Combinatorial.hpp.

Constructor & Destructor Documentation

template<typename Int = int64_t>
SUNphi::Combinatorial< Int >::Combinatorial ( const Vector< Int > &  nMaxPerSlot,
const int  nObj,
const bool  lastOrFirst = false 
)
inline

Constructor specifying the maximal number of objects per slot.

Parameters
nMaxPerSlotMaximal number of objects per slot
nObjNumber of objects
lastOrFirstStarts from first or last combo

Definition at line 305 of file Combinatorial.hpp.

Member Function Documentation

template<typename Int = int64_t>
bool SUNphi::Combinatorial< Int >::advance ( )
inline

Go to next combo, returning true if was possible to do it.

Slot to move

Returned value

Number of object up to the slot

Definition at line 164 of file Combinatorial.hpp.

template<typename Int = int64_t>
Int SUNphi::Combinatorial< Int >::assignToSlots ( Vector< Int > &  res,
Int  nObjToAss,
const Slot firstSlot,
const Slot pastLastSlot,
const Slot dSlot 
) const
inlineprivate

Assign n elements n the range, putting the maximum available in each of them

Returns the number of non-assigned elements

Parameters
resResult
nObjToAssNumber of elements to assign
firstSlotFirst slot where to assign
pastLastSlotSlot before which to stop assigning
dSlotOffset between slots

Definition at line 39 of file Combinatorial.hpp.

template<typename Int = int64_t>
Vector<Int> SUNphi::Combinatorial< Int >::getFirstOrLast ( const FIRST_OR_LAST firstLast) const
inlineprivate

Get the first or last combo.

Returned value

Number of objects to assign

First slot to assign

Last slot to assign

Offset to move

Residual objects to assign

Definition at line 65 of file Combinatorial.hpp.

template<typename Int = int64_t>
static bool SUNphi::Combinatorial< Int >::isPossibleToAccomodate ( const Vector< Int > &  nMaxPerSlot,
const int  nObj 
)
inlinestatic

Check if it is possible to combine the nObj into the slots.

Parameters
nMaxPerSlotMaximal number of objects per slot
nObjNumber of objects

Definition at line 110 of file Combinatorial.hpp.

template<typename Int = int64_t>
template<typename... Ts>
decltype(auto) SUNphi::Combinatorial< Int >::operator() ( Ts &&...  ts)
inline

Overload the operator() const method passing all args

Parameters
tsArguments

Definition at line 256 of file Combinatorial.hpp.

template<typename Int = int64_t>
bool SUNphi::Combinatorial< Int >::rewind ( )
inline

Go to previous combo, returning true if was possible to do it.

Slot to move

Returned value

Number of object before the slot

Definition at line 201 of file Combinatorial.hpp.


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