DGtal  1.5.beta
DGtal::ModuloComputer< TInteger > Class Template Reference

implements basic functions on modular arithmetic. More...

#include <DGtal/arithmetic/ModuloComputer.h>

Public Types

typedef TInteger Integer
 
typedef NumberTraits< Integer >::ParamType IntegerParamType
 
typedef NumberTraits< TInteger >::UnsignedVersion UnsignedInteger
 
typedef NumberTraits< UnsignedInteger >::ParamType UnsignedIntegerParamType
 

Public Member Functions

 BOOST_CONCEPT_ASSERT ((concepts::CInteger< Integer >))
 
 ModuloComputer (UnsignedIntegerParamType m)
 
void increment (UnsignedInteger &i) const
 
void decrement (UnsignedInteger &i) const
 
UnsignedInteger next (UnsignedIntegerParamType i) const
 
UnsignedInteger previous (UnsignedIntegerParamType i) const
 
UnsignedInteger cast (IntegerParamType i) const
 
bool less (UnsignedIntegerParamType i, UnsignedIntegerParamType j) const
 
UnsignedInteger posDiff (UnsignedIntegerParamType j, UnsignedIntegerParamType i) const
 
void selfDisplay (std::ostream &out) const
 
bool isValid () const
 

Protected Member Functions

 ModuloComputer ()
 

Private Member Functions

 ModuloComputer (const ModuloComputer &other)
 
ModuloComputeroperator= (const ModuloComputer &other)
 

Private Attributes

UnsignedInteger k
 

Detailed Description

template<typename TInteger>
class DGtal::ModuloComputer< TInteger >

implements basic functions on modular arithmetic.

Description of template class 'ModuloComputer'

Template Parameters
TIntegertype of integer.

Example:

...
//Construct an arithmetic modulo 15
// Note that MyInteger must be a model of the concept CInteger
ModuloComputer<MyInteger> modular(15);
typedef MyInteger::UnsignedVersion myUnsignedInteger;
myUnsignedInteger a;
a = modular.cast( 2 ); //a contains the value 2
a = modular.cast( -1 ); //a contains the value 14
modular.increment( a ); //a contains the value 0
...

Definition at line 79 of file ModuloComputer.h.

Member Typedef Documentation

◆ Integer

template<typename TInteger >
typedef TInteger DGtal::ModuloComputer< TInteger >::Integer

Definition at line 82 of file ModuloComputer.h.

◆ IntegerParamType

template<typename TInteger >
typedef NumberTraits<Integer>::ParamType DGtal::ModuloComputer< TInteger >::IntegerParamType

Definition at line 83 of file ModuloComputer.h.

◆ UnsignedInteger

template<typename TInteger >
typedef NumberTraits<TInteger>::UnsignedVersion DGtal::ModuloComputer< TInteger >::UnsignedInteger

Definition at line 85 of file ModuloComputer.h.

◆ UnsignedIntegerParamType

template<typename TInteger >
typedef NumberTraits<UnsignedInteger>::ParamType DGtal::ModuloComputer< TInteger >::UnsignedIntegerParamType

Definition at line 86 of file ModuloComputer.h.

Constructor & Destructor Documentation

◆ ModuloComputer() [1/3]

template<typename TInteger >
DGtal::ModuloComputer< TInteger >::ModuloComputer ( UnsignedIntegerParamType  m)

Initializes the modulo computer with the value [m].

Parameters
many non-zero integer.

◆ ModuloComputer() [2/3]

template<typename TInteger >
DGtal::ModuloComputer< TInteger >::ModuloComputer ( )
protected

Constructor. Forbidden by default (protected to avoid g++ warnings).

◆ ModuloComputer() [3/3]

template<typename TInteger >
DGtal::ModuloComputer< TInteger >::ModuloComputer ( const ModuloComputer< TInteger > &  other)
private

Copy constructor.

Parameters
otherthe object to clone. Forbidden by default.

Member Function Documentation

◆ BOOST_CONCEPT_ASSERT()

template<typename TInteger >
DGtal::ModuloComputer< TInteger >::BOOST_CONCEPT_ASSERT ( (concepts::CInteger< Integer >)  )

◆ cast()

template<typename TInteger >
UnsignedInteger DGtal::ModuloComputer< TInteger >::cast ( IntegerParamType  i) const
Parameters
iany integer value.
Returns
the value of [i] modulo [k]. NB: O ( i/k ) operation.

Referenced by testModuloComputer().

◆ decrement()

template<typename TInteger >
void DGtal::ModuloComputer< TInteger >::decrement ( UnsignedInteger i) const

Decrement the value [i] modulo.

Parameters
iany value between 0 and [k] (excluded).

◆ increment()

template<typename TInteger >
void DGtal::ModuloComputer< TInteger >::increment ( UnsignedInteger i) const

Increment the value [i] modulo.

Parameters
iany value between 0 and [k] (excluded).

Referenced by testModuloComputer().

◆ isValid()

template<typename TInteger >
bool DGtal::ModuloComputer< TInteger >::isValid ( ) const

Checks the validity/consistency of the object.

Returns
'true' if the object is valid, 'false' otherwise.

◆ less()

template<typename TInteger >
bool DGtal::ModuloComputer< TInteger >::less ( UnsignedIntegerParamType  i,
UnsignedIntegerParamType  j 
) const

Less comparator modulo. Be careful, modulo comparisons have no sense when the absolute difference of the values are around k / 2.

Parameters
iany value between 0 and [k] (excluded).
jany value between 0 and [k] (excluded).
Returns
'true' if [i] strictly precedes [j] in a window 'floor([k]/2)'.

◆ next()

template<typename TInteger >
UnsignedInteger DGtal::ModuloComputer< TInteger >::next ( UnsignedIntegerParamType  i) const
Parameters
iany value between 0 and [k] (excluded).
Returns
the incremented value of [i] modulo [k].

◆ operator=()

template<typename TInteger >
ModuloComputer& DGtal::ModuloComputer< TInteger >::operator= ( const ModuloComputer< TInteger > &  other)
private

Assignment.

Parameters
otherthe object to copy.
Returns
a reference on 'this'. Forbidden by default.

◆ posDiff()

template<typename TInteger >
UnsignedInteger DGtal::ModuloComputer< TInteger >::posDiff ( UnsignedIntegerParamType  j,
UnsignedIntegerParamType  i 
) const

Performs j - i modulo, assuming less(i,j) is true.

Parameters
jany value between 0 and [k] (excluded).
iany value between 0 and [k] (excluded).
Returns
the value j - i, always positive.

◆ previous()

template<typename TInteger >
UnsignedInteger DGtal::ModuloComputer< TInteger >::previous ( UnsignedIntegerParamType  i) const
Parameters
iany value between 0 and [k] (excluded).
Returns
the decremented value of [i] modulo [k].

◆ selfDisplay()

template<typename TInteger >
void DGtal::ModuloComputer< TInteger >::selfDisplay ( std::ostream &  out) const

Writes/Displays the object on an output stream.

Parameters
outthe output stream where the object is written.

Field Documentation

◆ k

template<typename TInteger >
UnsignedInteger DGtal::ModuloComputer< TInteger >::k
private

Modulo of all computations.

Definition at line 164 of file ModuloComputer.h.


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