DGtal  0.9.3beta
Public Types | Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes
DGtal::ModuloComputer< TInteger > Class Template Reference

#include <DGtal/arithmetic/ModuloComputer.h>

Collaboration diagram for DGtal::ModuloComputer< TInteger >:
[legend]

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

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

Definition at line 82 of file ModuloComputer.h.

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

Definition at line 83 of file ModuloComputer.h.

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

Definition at line 85 of file ModuloComputer.h.

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

Definition at line 86 of file ModuloComputer.h.

Constructor & Destructor Documentation

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

Initializes the modulo computer with the value [m].

Parameters
many non-zero integer.
template<typename TInteger>
DGtal::ModuloComputer< TInteger >::ModuloComputer ( )
protected

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

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

template<typename TInteger>
DGtal::ModuloComputer< TInteger >::BOOST_CONCEPT_ASSERT ( (concepts::CInteger< Integer >)  )
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.
template<typename TInteger>
void DGtal::ModuloComputer< TInteger >::decrement ( UnsignedInteger i) const

Decrement the value [i] modulo.

Parameters
iany value between 0 and [k] (excluded).
template<typename TInteger>
void DGtal::ModuloComputer< TInteger >::increment ( UnsignedInteger i) const

Increment the value [i] modulo.

Parameters
iany value between 0 and [k] (excluded).
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.
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)'.
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].
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.
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.
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].
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

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: