DGtal
0.6.devel
|
#include <IntegerComputer.h>
Public Types | |
typedef IntegerComputer< TInteger > | Self |
typedef NumberTraits< TInteger > ::SignedVersion | Integer |
typedef NumberTraits< Integer > ::ParamType | IntegerParamType |
typedef NumberTraits< TInteger > ::UnsignedVersion | UnsignedInteger |
typedef NumberTraits < UnsignedInteger >::ParamType | UnsignedIntegerParamType |
typedef SpaceND< 2, Integer > ::Point | Point2I |
typedef SpaceND< 2, Integer > ::Vector | Vector2I |
typedef SpaceND< 3, Integer > ::Point | Point3I |
typedef SpaceND< 3, Integer > ::Vector | Vector3I |
Static Public Member Functions | |
static bool | isZero (IntegerParamType a) |
static bool | isNotZero (IntegerParamType a) |
static bool | isPositive (IntegerParamType a) |
static bool | isNegative (IntegerParamType a) |
static bool | isPositiveOrZero (IntegerParamType a) |
static bool | isNegativeOrZero (IntegerParamType a) |
static Integer | abs (IntegerParamType a) |
static Integer | max (IntegerParamType a, IntegerParamType b) |
static Integer | max (IntegerParamType a, IntegerParamType b, IntegerParamType c) |
static Integer | min (IntegerParamType a, IntegerParamType b) |
static Integer | min (IntegerParamType a, IntegerParamType b, IntegerParamType c) |
static Integer | staticGcd (IntegerParamType a, IntegerParamType b) |
Private Attributes | |
Integer | _m_a |
Integer | _m_b |
Integer | _m_a0 |
Integer | _m_a1 |
Integer | _m_q |
Integer | _m_r |
std::vector< Integer > | _m_bezout [4] |
Vector2I | _m_v |
Vector2I | _m_v0 |
Vector2I | _m_v1 |
Integer | _m_c0 |
Integer | _m_c1 |
Integer | _m_c2 |
Aim: This class gathers several types and methods to make computation with integers.
Description of template class 'IntegerComputer'
This class is especially useful with using big integers (like GMP), since a substantial part of the execution time cames from the allocation/desallocation of integers. The idea is that the user instantiate once this object and computes gcd, bezout, continued fractions with it.
To be thread-safe, each thread must instantiate an IntegerComputer.
It is a model of boost::CopyConstructible, boost::DefaultConstructible, boost::Assignable. All its member data are mutable.
It is a backport of ImaGene.
TInteger | any model of integer (CInteger), like int , long int, int64_t , BigInteger (when GMP is installed). |
Definition at line 82 of file IntegerComputer.h.
typedef NumberTraits<TInteger>::SignedVersion DGtal::IntegerComputer< TInteger >::Integer |
Definition at line 87 of file IntegerComputer.h.
typedef NumberTraits<Integer>::ParamType DGtal::IntegerComputer< TInteger >::IntegerParamType |
Definition at line 88 of file IntegerComputer.h.
typedef SpaceND<2,Integer>::Point DGtal::IntegerComputer< TInteger >::Point2I |
Definition at line 93 of file IntegerComputer.h.
typedef SpaceND<3,Integer>::Point DGtal::IntegerComputer< TInteger >::Point3I |
Definition at line 95 of file IntegerComputer.h.
typedef IntegerComputer<TInteger> DGtal::IntegerComputer< TInteger >::Self |
Definition at line 86 of file IntegerComputer.h.
typedef NumberTraits<TInteger>::UnsignedVersion DGtal::IntegerComputer< TInteger >::UnsignedInteger |
Definition at line 90 of file IntegerComputer.h.
typedef NumberTraits<UnsignedInteger>::ParamType DGtal::IntegerComputer< TInteger >::UnsignedIntegerParamType |
Definition at line 91 of file IntegerComputer.h.
typedef SpaceND<2,Integer>::Vector DGtal::IntegerComputer< TInteger >::Vector2I |
Definition at line 94 of file IntegerComputer.h.
typedef SpaceND<3,Integer>::Vector DGtal::IntegerComputer< TInteger >::Vector3I |
Definition at line 96 of file IntegerComputer.h.
|
inline |
|
inline |
Constructor. Each thread must have its own instance for all computations. Such object stores several local variables to limit the number of memory allocations.
Does nothing (member data are allocated, but their values are not used except during the execution of methods).
Definition at line 49 of file IntegerComputer.ih.
|
inline |
Copy constructor.
Does nothing (member data are allocated, but their values are not used except during the execution of methods).
other | the object to clone. |
Definition at line 54 of file IntegerComputer.ih.
|
inlinestatic |
a | any integer. |
Definition at line 125 of file IntegerComputer.ih.
DGtal::IntegerComputer< TInteger >::BOOST_CONCEPT_ASSERT | ( | (CInteger< Integer >) | ) |
DGtal::IntegerComputer< TInteger >::BOOST_CONCEPT_ASSERT | ( | (CUnsignedInteger< UnsignedInteger >) | ) |
|
inline |
Computes the ceil value of na/nb.
na | any integer. |
nb | any integer. |
Definition at line 213 of file IntegerComputer.ih.
|
inline |
Returns the fraction corresponding to the given quotients, more precisely its k-th principal convergent. When k >= quotients.size() - 1, it is the inverse of the function getCFrac.
quotients | the sequence of partial quotients. |
k | the desired partial convergent. |
Definition at line 365 of file IntegerComputer.ih.
|
inline |
Computes and returns the cross product of u and v.
u | any vector in Z2. |
v | any vector in Z2. |
Definition at line 405 of file IntegerComputer.ih.
Referenced by DGtal::FrechetShortcut< TIterator, TInteger >::Backpath::updateIntervals().
|
inline |
Computes and returns the dot product of u and v.
u | any vector in Z2. |
v | any vector in Z2. |
Definition at line 427 of file IntegerComputer.ih.
Referenced by DGtal::FrechetShortcut< TIterator, TInteger >::Tools::angleVectVect(), DGtal::FrechetShortcut< TIterator, TInteger >::Backpath::updateIntervals(), and DGtal::FrechetShortcut< TIterator, TInteger >::Backpath::updateOcculters().
|
inline |
DGtal::IntegerComputer< TInteger >::Vector2I DGtal::IntegerComputer< TInteger >::extendedEuclid | ( | IntegerParamType | a, |
IntegerParamType | b, | ||
IntegerParamType | c | ||
) | const |
Returns a solution of the Diophantine equation: a x + b y = c. The integer c should be a multiple of the gcd of a and b. Uses the extended Euclid algorithm to do it, whose complexity is bounded by max(log(a),log(b)).
a | any integer. |
b | any integer. |
c | any integer (see above). |
Definition at line 448 of file IntegerComputer.ih.
References DGtal::abs().
|
inline |
Computes the floor value of na/nb.
na | any integer. |
nb | any integer. |
Definition at line 184 of file IntegerComputer.ih.
Referenced by DGtal::ClosedIntegerHalfPlane< TSpace >::ClosedIntegerHalfPlane().
|
inline |
Returns the greatest common divisor of a and b (a and b may be either positive or negative).
a | any integer. |
b | any integer. |
Definition at line 284 of file IntegerComputer.ih.
References DGtal::abs().
Referenced by DGtal::ClosedIntegerHalfPlane< TSpace >::ClosedIntegerHalfPlane(), DGtal::SternBrocot< TInteger, TQuotient >::fraction(), and DGtal::Pattern< TFraction >::Pattern().
|
inline |
Computes and push_backs the simple continued fraction of a / b. (positive) and b (positive). For instance, 5/13=[0;2,1,1,2], which is exactly what is pushed at the back of quotients.
quotients | (modifies) adds to the back of the vector the quotients of the continued fraction of a/b. |
a | any positive integer. |
b | any positive integer. |
Definition at line 323 of file IntegerComputer.ih.
|
inline |
Computes and outputs the quotients of the simple continued fraction of a / b. (positive) and b (positive). For instance, 5/13=[0;2,1,1,2], which is exactly what is outputed with the OutputIterator outIt.
OutputIterator | a model of boost::OutputIterator |
outIt | an instance of output iterator that is used to write the successive quotients of the continued fraction of a/b. |
a | any positive integer. |
b | any positive integer. |
Definition at line 344 of file IntegerComputer.ih.
|
inline |
Computes the floor (fl) and the ceiling (ce) value of the real number k such that p + k u lies on the supporting line of the linear constraint N.p <= c.
Otherwise said: (u.N) fl <= c - p.N < (u.N) ce
fl | the greatest integer such that (u.N) fl <= c - p.N |
ce | the smallest integer such that c - p.N < (u.N) ce |
p | any vector in Z2 |
u | any vector in Z2 in the same quadrant as N. |
N | any vector in Z2 in the same quadrant as u. |
c | any integer. |
Definition at line 494 of file IntegerComputer.ih.
|
inline |
Computes the cross product of u and v.
cp | (returns) the cross product of u and v. |
u | any vector in Z2. |
v | any vector in Z2. |
Definition at line 416 of file IntegerComputer.ih.
|
inline |
Computes and returns the dot product of u and v.
dp | (returns) the dot product of u and v. |
u | any vector in Z2. |
v | any vector in Z2. |
Definition at line 438 of file IntegerComputer.ih.
Referenced by DGtal::ClosedIntegerHalfPlane< TSpace >::ClosedIntegerHalfPlane().
|
inline |
Computes and returns the dot product of u and v.
dp | (returns) the dot product of u and v. |
u | any vector in Z3. |
v | any vector in Z3. |
Definition at line 566 of file IntegerComputer.ih.
|
inline |
Computes the euclidean division of a/b, returning quotient and remainder. May be faster than computing separately quotient and remainder, depending on the integral type in use.
q | (returns) the quotient of a/b. |
r | (returns) the remainder of a/b. |
a | any integer. |
b | any integer. |
Definition at line 173 of file IntegerComputer.ih.
Referenced by DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::Fraction(), and DGtal::LighterSternBrocot< TInteger, TQuotient, TMap >::Fraction::Fraction().
|
inline |
Computes the floor and ceil value of na/nb.
fl | (returns) the floor value of na/nb. |
ce | (returns) the ceil value of na/nb. |
na | any integer. |
nb | any integer. |
Definition at line 242 of file IntegerComputer.ih.
|
inline |
Returns the greatest common divisor of a and b (a and b may be either positive or negative).
g | (returns) the gcd of a and b. |
a | any integer. |
b | any integer. |
Definition at line 303 of file IntegerComputer.ih.
References DGtal::abs().
|
inline |
Compute the valid bezout vector v of u such that A+v satifies the constraints C2 and such that A+v+u doesn't satify the constraint C2.
(A+v).N2 <= c2, (A+v+u).N2 > c2.
The constraint (N,c) is used like this: if the Bezout is such that (A+v).N > c, then v <- -v. Thus v is oriented toward the constraint.
If ! compute_v, v is used as is. The constraint N.(A+v) <= c should be satisfied.
v | (modifies) a Bezout vector for u, with the constraints above. |
A | any point in Z2. |
u | any vector in Z2. |
N | any vector in Z2, defining the first constraint. |
c | the integer for the first constraint. |
N2 | any vector in Z2, defining the second constraint. |
c2 | the integer for the second constraint. |
compute_v | tells if v should be recomputed (true) or is already given (false), default to true. |
Definition at line 512 of file IntegerComputer.ih.
|
inlinestatic |
a | any integer. |
Definition at line 98 of file IntegerComputer.ih.
|
inlinestatic |
a | any integer. |
Definition at line 116 of file IntegerComputer.ih.
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
a | any integer. |
Definition at line 107 of file IntegerComputer.ih.
|
inline |
Checks the validity/consistency of the object.
Definition at line 597 of file IntegerComputer.ih.
|
inlinestatic |
|
inlinestatic |
a | any integer. |
b | any integer. |
Definition at line 137 of file IntegerComputer.ih.
|
inlinestatic |
a | any integer. |
b | any integer. |
c | any integer. |
Definition at line 146 of file IntegerComputer.ih.
|
inlinestatic |
a | any integer. |
b | any integer. |
Definition at line 155 of file IntegerComputer.ih.
|
inlinestatic |
a | any integer. |
b | any integer. |
c | any integer. |
Definition at line 164 of file IntegerComputer.ih.
|
inline |
Assignment.
Does nothing (member data are allocated, but their values are not used except during the execution of methods).
other | the object to copy. |
Definition at line 60 of file IntegerComputer.ih.
|
inline |
Makes p irreducible.
p | any vector in Z2. |
Definition at line 394 of file IntegerComputer.ih.
References DGtal::gcd().
|
inline |
Makes p irreducible.
p | any vector in Z3. |
Definition at line 543 of file IntegerComputer.ih.
References DGtal::gcd().
|
inline |
Writes/Displays the object on an output stream.
out | the output stream where the object is written. |
Definition at line 585 of file IntegerComputer.ih.
|
inlinestatic |
Returns the greatest common divisor of a and b (a and b may be either positive or negative).
a | any integer. |
b | any integer. |
Definition at line 264 of file IntegerComputer.ih.
References DGtal::abs().
|
mutableprivate |
Used to store parameter a.
Definition at line 497 of file IntegerComputer.h.
|
mutableprivate |
Used to for successive computation in gcd.
Definition at line 501 of file IntegerComputer.h.
|
mutableprivate |
Used to for successive computation in gcd.
Definition at line 503 of file IntegerComputer.h.
|
mutableprivate |
Used to store parameter b.
Definition at line 499 of file IntegerComputer.h.
|
mutableprivate |
Used to represent the variables during an extended Euclid computation, [0] are remainders, [1] are quotients, [2] are successive a, [3] are successive b.
Definition at line 511 of file IntegerComputer.h.
|
mutableprivate |
Used to represent scalar products.
Definition at line 519 of file IntegerComputer.h.
|
mutableprivate |
Used to represent scalar products.
Definition at line 521 of file IntegerComputer.h.
|
mutableprivate |
Used to represent scalar products.
Definition at line 523 of file IntegerComputer.h.
|
mutableprivate |
Used to represent a quotient.
Definition at line 505 of file IntegerComputer.h.
|
mutableprivate |
Used to represent a remainder.
Definition at line 507 of file IntegerComputer.h.
|
mutableprivate |
Used to represent the Bezout vector.
Definition at line 513 of file IntegerComputer.h.
|
mutableprivate |
Used to represent vectors.
Definition at line 515 of file IntegerComputer.h.
|
mutableprivate |
Used to represent vectors.
Definition at line 517 of file IntegerComputer.h.