DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Public Types | Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes
DGtal::ModuloComputer< TInteger > Class Template Reference

#include <ModuloComputer.h>

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

Public Types

typedef NumberTraits< TInteger >
::SignedVersion 
Integer
typedef NumberTraits< Integer >
::ParamType 
IntegerParamType
typedef NumberTraits< TInteger >
::UnsignedVersion 
UnsignedInteger
typedef NumberTraits
< 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'

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 80 of file ModuloComputer.h.


Member Typedef Documentation

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

Definition at line 83 of file ModuloComputer.h.

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

Definition at line 84 of file ModuloComputer.h.

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

Definition at line 86 of file ModuloComputer.h.

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

Definition at line 87 of file ModuloComputer.h.


Constructor & Destructor Documentation

template<typename T >
DGtal::ModuloComputer< T >::ModuloComputer ( UnsignedIntegerParamType  m)
inline

Initializes the modulo computer with the value [m].

Parameters:
many non-zero integer.

Definition at line 48 of file ModuloComputer.ih.

: k( m )
{
}
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 ( (CInteger< Integer >)  )
template<typename TInteger>
DGtal::ModuloComputer< TInteger >::BOOST_CONCEPT_ASSERT ( (CUnsignedInteger< UnsignedInteger >)  )
template<typename T >
DGtal::ModuloComputer< T >::UnsignedInteger DGtal::ModuloComputer< T >::cast ( IntegerParamType  i) const
inline
Parameters:
iany integer value.
Returns:
the value of [i] modulo [k]. NB: O ( i/k ) operation.
Parameters:
iany integer value.
Returns:
the value of [i] modulo [k].

Definition at line 119 of file ModuloComputer.ih.

Referenced by DGtal::OrderedAlphabet::duvalPPMod().

{
Integer tmp = i;
while ( tmp < 0 ) tmp += k;
while ( ip >= k ) ip -= k;
return ip;
}
template<typename T >
void DGtal::ModuloComputer< T >::decrement ( UnsignedInteger i) const
inline

Decrement the value [i] modulo.

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

Definition at line 78 of file ModuloComputer.ih.

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

{
if ( i == 0 ) i = k;
--i;
}
template<typename T >
void DGtal::ModuloComputer< T >::increment ( UnsignedInteger i) const
inline

Increment the value [i] modulo.

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

Definition at line 65 of file ModuloComputer.ih.

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

{
if ( ++i == k ) i = 0;
}
template<typename T >
bool DGtal::ModuloComputer< T >::isValid ( ) const
inline

Checks the validity/consistency of the object.

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

Definition at line 186 of file ModuloComputer.ih.

{
return true;
}
template<typename T >
bool DGtal::ModuloComputer< T >::less ( UnsignedIntegerParamType  i,
UnsignedIntegerParamType  j 
) const
inline

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

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)'.
See also:
k

Definition at line 140 of file ModuloComputer.ih.

{
Integer d = ( (T) j ) - ( (T) i );
if ( d > 0 )
return d < (T) ( k / 2 );
else
return (-d) >= (T) ( k / 2 );
}
template<typename T >
DGtal::ModuloComputer< T >::UnsignedInteger DGtal::ModuloComputer< T >::next ( UnsignedIntegerParamType  i) const
inline
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 T >
DGtal::ModuloComputer< T >::UnsignedInteger DGtal::ModuloComputer< T >::posDiff ( UnsignedIntegerParamType  j,
UnsignedIntegerParamType  i 
) const
inline

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.

Definition at line 160 of file ModuloComputer.ih.

{
return ( i <= j ) ? j - i : j + k - i;
}
template<typename T >
DGtal::ModuloComputer< T >::UnsignedInteger DGtal::ModuloComputer< T >::previous ( UnsignedIntegerParamType  i) const
inline
Parameters:
iany value between 0 and [k] (excluded).
Returns:
the decremented value of [i] modulo [k].

Definition at line 106 of file ModuloComputer.ih.

Referenced by DGtal::AngleLinearMinimizer::getEnergy(), DGtal::AngleLinearMinimizer::getFormerEnergy(), DGtal::AngleLinearMinimizer::getFormerGradient(), DGtal::AngleLinearMinimizer::getGradient(), DGtal::AngleLinearMinimizer::oneStep(), and DGtal::AngleLinearMinimizerByRelaxation::oneStep().

{
return ( i == 0 ) ? k - 1 : i - 1;
}
template<typename T >
void DGtal::ModuloComputer< T >::selfDisplay ( std::ostream &  out) const
inline

Writes/Displays the object on an output stream.

Parameters:
outthe output stream where the object is written.

Definition at line 174 of file ModuloComputer.ih.

{
out << "[ModuloComputer]";
}

Field Documentation

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

Modulo of all computations.

Definition at line 166 of file ModuloComputer.h.


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