DGtal
0.6.devel
|
#include <LightSternBrocot.h>
Public Types | |
typedef TInteger | Integer |
typedef TQuotient | Quotient |
typedef LightSternBrocot < TInteger, TQuotient, TMap > | SternBrocotTree |
typedef SternBrocotTree::Fraction | Self |
typedef NumberTraits< Integer > ::UnsignedVersion | UnsignedInteger |
typedef std::pair< Quotient, Quotient > | Value |
typedef std::vector< Quotient > | CFracSequence |
typedef InputIteratorWithRankOnSequence < CFracSequence, Quotient > | ConstIterator |
typedef Value | value_type |
typedef ConstIterator | const_iterator |
typedef const value_type & | const_reference |
Public Member Functions | |
Fraction (Integer aP, Integer aQ, Fraction start=SternBrocotTree::zeroOverOne()) | |
Fraction (Node *sb_node=0, bool sup1=false) | |
Fraction (const Self &other) | |
Self & | operator= (const Self &other) |
bool | null () const |
Integer | p () const |
Integer | q () const |
Quotient | u () const |
Quotient | k () const |
bool | isSup1 () const |
Quotient | trueK () const |
Fraction | left () const |
Fraction | right () const |
bool | even () const |
bool | odd () const |
Fraction | ancestor () const |
bool | isAncestorDirect () const |
Fraction | father () const |
Fraction | father (Quotient m) const |
Fraction | previousPartial () const |
Fraction | inverse () const |
Fraction | partial (Quotient kp) const |
Fraction | reduced (Quotient i) const |
void | push_back (const std::pair< Quotient, Quotient > "ient) |
void | pushBack (const std::pair< Quotient, Quotient > "ient) |
void | getSplit (Fraction &f1, Fraction &f2) const |
void | getSplitBerstel (Fraction &f1, Quotient &nb1, Fraction &f2, Quotient &nb2) const |
void | getCFrac (std::vector< Quotient > "ients) const |
bool | equals (Integer p1, Integer q1) const |
bool | lessThan (Integer p1, Integer q1) const |
bool | moreThan (Integer p1, Integer q1) const |
bool | operator== (const Fraction &other) const |
bool | operator!= (const Fraction &other) const |
bool | operator< (const Fraction &other) const |
bool | operator> (const Fraction &other) const |
void | selfDisplay (std::ostream &out) const |
ConstIterator | begin () const |
ConstIterator | end () const |
Protected Member Functions | |
Fraction | next (Quotient v) const |
Fraction | next1 (Quotient v) const |
Private Attributes | |
Node * | myNode |
bool | mySup1 |
This fraction is a model of CPositiveIrreducibleFraction.
It represents a positive irreducible fraction, i.e. some p/q qith gcd(p,q)=1. It is an inner class of LightSternBrocot. This representation of a fraction is simply a pointer to the corresponding node in this tree, plus a boolean indicating if it is bigger than 1/1.
Definition at line 195 of file LightSternBrocot.h.
typedef std::vector<Quotient> DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::CFracSequence |
Definition at line 203 of file LightSternBrocot.h.
typedef ConstIterator DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::const_iterator |
Definition at line 208 of file LightSternBrocot.h.
typedef const value_type& DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::const_reference |
Definition at line 209 of file LightSternBrocot.h.
typedef InputIteratorWithRankOnSequence<CFracSequence,Quotient> DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::ConstIterator |
Definition at line 204 of file LightSternBrocot.h.
typedef TInteger DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::Integer |
Definition at line 197 of file LightSternBrocot.h.
typedef TQuotient DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::Quotient |
Definition at line 198 of file LightSternBrocot.h.
typedef SternBrocotTree::Fraction DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::Self |
Definition at line 200 of file LightSternBrocot.h.
typedef LightSternBrocot<TInteger, TQuotient, TMap> DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::SternBrocotTree |
Definition at line 199 of file LightSternBrocot.h.
typedef NumberTraits<Integer>::UnsignedVersion DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::UnsignedInteger |
Definition at line 201 of file LightSternBrocot.h.
typedef std::pair<Quotient, Quotient> DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::Value |
Definition at line 202 of file LightSternBrocot.h.
typedef Value DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::value_type |
Definition at line 207 of file LightSternBrocot.h.
|
inline |
Creates the fraction aP/aQ. Complexity is in O(n) where n is the depth of continued fraction of aP/aQ.
aP | the numerator (>=0) |
aQ | the denominator (>=0) |
start | (optional) unused in this representation. |
Definition at line 65 of file LightSternBrocot.ih.
References DGtal::IntegerComputer< TInteger >::getEuclideanDiv(), DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::inverse(), DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::k(), DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::next(), DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::next1(), DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::oneOverZero(), DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::operator=(), and DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::zeroOverOne().
|
inline |
Default constructor.
sb_node | the associated node (or 0 for null fraction). |
sup1 | when 'true', the fraction is greater than 1/1 and represents q/p. |
Definition at line 101 of file LightSternBrocot.ih.
|
inline |
Copy constructor.
other | the object to clone. |
Definition at line 109 of file LightSternBrocot.ih.
|
inline |
Definition at line 405 of file LightSternBrocot.ih.
Referenced by DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::getCFrac(), and DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::reduced().
|
inline |
Definition at line 581 of file LightSternBrocot.ih.
|
inline |
Definition at line 592 of file LightSternBrocot.ih.
|
inline |
p1 | a numerator. |
q1 | a denominator. |
Definition at line 207 of file LightSternBrocot.ih.
|
inline |
Definition at line 387 of file LightSternBrocot.ih.
|
inline |
Definition at line 423 of file LightSternBrocot.ih.
Referenced by DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::getCFrac(), and DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::reduced().
|
inline |
m | a quotient between 1 and uk-1. |
Definition at line 435 of file LightSternBrocot.ih.
|
inline |
quotients | (returns) the coefficients of the continued fraction of 'this'. |
Definition at line 560 of file LightSternBrocot.ih.
References DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::ancestor(), DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::father(), DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Node::k, DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::myNode, and DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::u().
Referenced by DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::display().
|
inline |
Splitting formula, O(1) time complexity. This fraction should not be 0/1 or 1/0. NB: 'this' = [f1] [f2].
f1 | (returns) the left part of the split. |
f2 | (returns) the right part of the split. |
Definition at line 518 of file LightSternBrocot.ih.
|
inline |
Berstel splitting formula, O(1) time complexity. This fraction should not be 0/1 or 1/0. NB: 'this' = nb1*[f1] nb2*[f2]. Also, if 'this->k' is even then nb1=1, otherwise nb2=1.
f1 | (returns) the left part of the split (left pattern). |
nb1 | (returns) the number of repetition of the left pattern |
f2 | (returns) the right part of the split (right pattern). |
nb2 | (returns) the number of repetition of the right pattern |
Definition at line 536 of file LightSternBrocot.ih.
|
inline |
Definition at line 463 of file LightSternBrocot.ih.
Referenced by DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::Fraction().
|
inline |
Definition at line 414 of file LightSternBrocot.ih.
|
inline |
Definition at line 267 of file LightSternBrocot.h.
References DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::mySup1.
|
inline |
Definition at line 169 of file LightSternBrocot.ih.
References DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::instance(), DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::myOneOverOne, DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::myOneOverZero, and DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::myZeroOverOne.
Referenced by DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::display(), and DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::Fraction().
|
inline |
Definition at line 361 of file LightSternBrocot.ih.
|
inline |
p1 | a numerator. |
q1 | a denominator. |
Definition at line 216 of file LightSternBrocot.ih.
|
inline |
p1 | a numerator. |
q1 | a denominator. |
Definition at line 226 of file LightSternBrocot.ih.
|
inlineprotected |
Definition at line 278 of file LightSternBrocot.ih.
References DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Node::ascendant, DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Node::descendant2, DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::instance(), DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::myZeroOverOne, and DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::nbFractions.
Referenced by DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::Fraction().
|
inlineprotected |
Definition at line 328 of file LightSternBrocot.ih.
References DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::instance(), DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Node::k, DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::myNode, and DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::nbFractions.
Referenced by DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::Fraction().
|
inline |
Definition at line 132 of file LightSternBrocot.ih.
Referenced by DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::display().
|
inline |
Definition at line 396 of file LightSternBrocot.ih.
|
inline |
other | any fraction. |
Definition at line 249 of file LightSternBrocot.ih.
References operator==().
|
inline |
other | any fraction. |
Definition at line 258 of file LightSternBrocot.ih.
References DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::p(), and DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::q().
|
inline |
Assignment
other | the object to clone. |
Definition at line 118 of file LightSternBrocot.ih.
References DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::myNode, and DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::mySup1.
|
inline |
other | any fraction. |
Definition at line 236 of file LightSternBrocot.ih.
References DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::myNode, DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::mySup1, DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Node::p, and DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Node::q.
|
inline |
other | any fraction. |
Definition at line 267 of file LightSternBrocot.ih.
References DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::p(), and DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::q().
|
inline |
Definition at line 141 of file LightSternBrocot.ih.
Referenced by DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::display(), DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::operator<(), and DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::operator>().
|
inline |
|
inline |
Definition at line 454 of file LightSternBrocot.ih.
|
inline |
Modifies this fraction \form#77 to obtain the fraction \form#147. The depth of the quotient must be given, since continued fractions have two writings
\([u_0,...,u_k]\) and \([u_0,...,u_k - 1, 1]\).
Useful to create output iterators, for instance with @code typedef ... Fraction; Fraction f; std::back_insert_iterator<Fraction> itout = std::back_inserter( f ); @endcode @param quotient the pair \form#76.
Definition at line 499 of file LightSternBrocot.ih.
|
inline |
Modifies this fraction \form#77 to obtain the fraction \form#147. The depth of the quotient must be given, since continued fractions have two writings
\([u_0,...,u_k]\) and \([u_0,...,u_k - 1, 1]\).
See push_back for creating output iterators. @param quotient the pair \form#76.
Definition at line 508 of file LightSternBrocot.ih.
|
inline |
Definition at line 150 of file LightSternBrocot.ih.
Referenced by DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::display(), DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::operator<(), and DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::operator>().
|
inline |
i | a positive integer smaller or equal to k()+2. |
Definition at line 482 of file LightSternBrocot.ih.
References DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::ancestor(), DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::father(), DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Node::k, and DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::myNode.
|
inline |
Definition at line 374 of file LightSternBrocot.ih.
|
inline |
Writes/Displays the fraction on an output stream.
out | the output stream where the object is written. |
Definition at line 602 of file LightSternBrocot.ih.
|
inline |
Definition at line 269 of file LightSternBrocot.h.
References DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Node::k, and DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::myNode.
|
inline |
Definition at line 159 of file LightSternBrocot.ih.
Referenced by DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::display(), and DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::getCFrac().
|
private |
The pointer to the corresponding node in the Stern-Brocot tree, i.e. the node p/q if p <= q or the node q/p otherwise.
Definition at line 215 of file LightSternBrocot.h.
Referenced by DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::getCFrac(), DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::next1(), DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::operator=(), DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::operator==(), DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::reduced(), and DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::trueK().
|
private |
When 'true', the fraction is greater than 1/1 (to its right).
Definition at line 217 of file LightSternBrocot.h.
Referenced by DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::isSup1(), DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::operator=(), and DGtal::LightSternBrocot< TInteger, TQuotient, TMap >::Fraction::operator==().