Public Types | Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes

DGtal::ModuloComputer< TInteger > Class Template Reference

implements basic functions on modular arithmetic. More...

#include <ModuloComputer.h>

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

Public Types

typedef IntegerTraits
< TInteger >::SignedVersion 
Integer
typedef IntegerTraits< Integer >
::ParamType 
IntegerParamType
typedef IntegerTraits
< TInteger >::UnsignedVersion 
UnsignedInteger
typedef IntegerTraits
< UnsignedInteger >::ParamType 
UnsignedIntegerParamType

Public Member Functions

 BOOST_CONCEPT_ASSERT ((CInteger< Integer >))
 BOOST_CONCEPT_ASSERT ((CUnsignedInteger< UnsignedInteger >))
 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'

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
   ...

Member Typedef Documentation

template<typename TInteger>
typedef IntegerTraits<TInteger>::SignedVersion DGtal::ModuloComputer< TInteger >::Integer
template<typename TInteger>
typedef IntegerTraits<Integer>::ParamType DGtal::ModuloComputer< TInteger >::IntegerParamType
template<typename TInteger>
typedef IntegerTraits<TInteger>::UnsignedVersion DGtal::ModuloComputer< TInteger >::UnsignedInteger
template<typename TInteger>
typedef IntegerTraits<UnsignedInteger>::ParamType DGtal::ModuloComputer< TInteger >::UnsignedIntegerParamType

Constructor & Destructor Documentation

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

Initializes the modulo computer with the value [m].

Parameters:
m any 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:
other the object to clone. Forbidden by default.

Member Function Documentation

template<typename TInteger>
DGtal::ModuloComputer< TInteger >::BOOST_CONCEPT_ASSERT ( (CInteger< Integer >)   ) 
template<typename TInteger>
DGtal::ModuloComputer< TInteger >::BOOST_CONCEPT_ASSERT ( (CUnsignedInteger< UnsignedInteger >)   ) 
template<typename TInteger>
UnsignedInteger DGtal::ModuloComputer< TInteger >::cast ( IntegerParamType  i  )  const
Parameters:
i any integer value.
Returns:
the value of [i] modulo [k].
See also:
k

Referenced by DGtal::OrderedAlphabet::duvalPPMod(), and testModuloComputer().

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

Decrement the value [i] modulo.

Parameters:
i any value between 0 and [k] (excluded).
See also:
k

Referenced by DGtal::FreemanChain< TInteger >::cleanOuterSpikes().

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

Increment the value [i] modulo.

Parameters:
i any value between 0 and [k] (excluded).
See also:
k

Referenced by DGtal::FreemanChain< TInteger >::cleanOuterSpikes(), DGtal::OrderedAlphabet::duvalPPMod(), DGtal::OrderedAlphabet::firstLyndonFactorMod(), and testModuloComputer().

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:
i any value between 0 and [k] (excluded).
j any value between 0 and [k] (excluded).
Returns:
'true' if [i] strictly precedes [j] in a window 'floor([k]/2)'.
See also:
k
template<typename TInteger>
UnsignedInteger DGtal::ModuloComputer< TInteger >::next ( UnsignedIntegerParamType  i  )  const
Parameters:
i any value between 0 and [k] (excluded).
Returns:
the incremented value of [i] modulo [k].
See also:
k

Referenced by DGtal::FreemanChain< TInteger >::cleanOuterSpikes(), DGtal::OrderedAlphabet::duvalPPMod(), and DGtal::OrderedAlphabet::firstLyndonFactorMod().

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

Assignment.

Parameters:
other the 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:
j any value between 0 and [k] (excluded).
i any value between 0 and [k] (excluded).
Returns:
the value j - i, always positive.
See also:
k
template<typename TInteger>
UnsignedInteger DGtal::ModuloComputer< TInteger >::previous ( UnsignedIntegerParamType  i  )  const
Parameters:
i any value between 0 and [k] (excluded).
Returns:
the decremented value of [i] modulo [k].
See also:
k
template<typename TInteger>
void DGtal::ModuloComputer< TInteger >::selfDisplay ( std::ostream &  out  )  const

Writes/Displays the object on an output stream.

Parameters:
out the output stream where the object is written.

Field Documentation

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

Modulo of all computations.


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