DGtal
0.6.devel
|
#include <LighterSternBrocot.h>
Public Types | |
typedef TInteger | Integer |
typedef TQuotient | Quotient |
typedef LighterSternBrocot < 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 | child (Quotient v) const |
Fraction | origin () const |
Fraction | next (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 LighterSternBrocot. 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 217 of file LighterSternBrocot.h.
typedef std::vector<Quotient> DGtal::LighterSternBrocot< TInteger, TQuotient, TMap >::Fraction::CFracSequence |
Definition at line 225 of file LighterSternBrocot.h.
typedef ConstIterator DGtal::LighterSternBrocot< TInteger, TQuotient, TMap >::Fraction::const_iterator |
Definition at line 230 of file LighterSternBrocot.h.
typedef const value_type& DGtal::LighterSternBrocot< TInteger, TQuotient, TMap >::Fraction::const_reference |
Definition at line 231 of file LighterSternBrocot.h.
typedef InputIteratorWithRankOnSequence<CFracSequence,Quotient> DGtal::LighterSternBrocot< TInteger, TQuotient, TMap >::Fraction::ConstIterator |
Definition at line 226 of file LighterSternBrocot.h.
typedef TInteger DGtal::LighterSternBrocot< TInteger, TQuotient, TMap >::Fraction::Integer |
Definition at line 219 of file LighterSternBrocot.h.
typedef TQuotient DGtal::LighterSternBrocot< TInteger, TQuotient, TMap >::Fraction::Quotient |
Definition at line 220 of file LighterSternBrocot.h.
typedef SternBrocotTree::Fraction DGtal::LighterSternBrocot< TInteger, TQuotient, TMap >::Fraction::Self |
Definition at line 222 of file LighterSternBrocot.h.
typedef LighterSternBrocot<TInteger, TQuotient, TMap> DGtal::LighterSternBrocot< TInteger, TQuotient, TMap >::Fraction::SternBrocotTree |
Definition at line 221 of file LighterSternBrocot.h.
typedef NumberTraits<Integer>::UnsignedVersion DGtal::LighterSternBrocot< TInteger, TQuotient, TMap >::Fraction::UnsignedInteger |
Definition at line 223 of file LighterSternBrocot.h.
typedef std::pair<Quotient, Quotient> DGtal::LighterSternBrocot< TInteger, TQuotient, TMap >::Fraction::Value |
Definition at line 224 of file LighterSternBrocot.h.
typedef Value DGtal::LighterSternBrocot< TInteger, TQuotient, TMap >::Fraction::value_type |
Definition at line 229 of file LighterSternBrocot.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 148 of file LighterSternBrocot.ih.
References DGtal::LighterSternBrocot< TInteger, TQuotient, TMap >::Node::child(), DGtal::IntegerComputer< TInteger >::getEuclideanDiv(), DGtal::LighterSternBrocot< TInteger, TQuotient, TMap >::instance(), DGtal::LighterSternBrocot< TInteger, TQuotient, TMap >::myOneOverZero, DGtal::LighterSternBrocot< TInteger, TQuotient, TMap >::operator=(), and DGtal::LighterSternBrocot< TInteger, TQuotient, TMap >::zeroOverOne().
|
inline |
Default constructor.
sb_node | the associated node (or 0 for null fraction). |
sup1 | when 'false', the fraction is smaller greater than 1/1 and represents q/p. |
Definition at line 182 of file LighterSternBrocot.ih.
|
inline |
Copy constructor.
other | the object to clone. |
Definition at line 190 of file LighterSternBrocot.ih.
|
inline |
|
inline |
Definition at line 663 of file LighterSternBrocot.ih.
|
inlineprotected |
|
inline |
Definition at line 674 of file LighterSternBrocot.ih.
|
inline |
p1 | a numerator. |
q1 | a denominator. |
Definition at line 271 of file LighterSternBrocot.ih.
|
inline |
Definition at line 388 of file LighterSternBrocot.ih.
|
inline |
|
inline |
m | a quotient between 1 and uk-1. |
Definition at line 451 of file LighterSternBrocot.ih.
|
inline |
quotients | (returns) the coefficients of the continued fraction of 'this'. |
Definition at line 638 of file LighterSternBrocot.ih.
References DGtal::LighterSternBrocot< TInteger, TQuotient, TMap >::Fraction::origin(), and DGtal::LighterSternBrocot< TInteger, TQuotient, TMap >::Fraction::u().
Referenced by DGtal::LighterSternBrocot< 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 597 of file LighterSternBrocot.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 615 of file LighterSternBrocot.ih.
|
inline |
Definition at line 472 of file LighterSternBrocot.ih.
Referenced by DGtal::LighterSternBrocot< TInteger, TQuotient, TMap >::Fraction::pushBack().
|
inline |
Definition at line 433 of file LighterSternBrocot.ih.
|
inline |
Definition at line 288 of file LighterSternBrocot.h.
References DGtal::LighterSternBrocot< TInteger, TQuotient, TMap >::Fraction::mySup1.
|
inline |
Definition at line 252 of file LighterSternBrocot.ih.
Referenced by DGtal::LighterSternBrocot< TInteger, TQuotient, TMap >::display().
|
inline |
Definition at line 356 of file LighterSternBrocot.ih.
References DGtal::LighterSternBrocot< TInteger, TQuotient, TMap >::Node::child(), DGtal::LighterSternBrocot< TInteger, TQuotient, TMap >::instance(), DGtal::LighterSternBrocot< TInteger, TQuotient, TMap >::myOneOverZero, DGtal::LighterSternBrocot< TInteger, TQuotient, TMap >::oneOverOne(), and DGtal::LighterSternBrocot< TInteger, TQuotient, TMap >::Node::origin().
|
inline |
p1 | a numerator. |
q1 | a denominator. |
Definition at line 280 of file LighterSternBrocot.ih.
|
inline |
p1 | a numerator. |
q1 | a denominator. |
Definition at line 290 of file LighterSternBrocot.ih.
|
inlineprotected |
Definition at line 342 of file LighterSternBrocot.ih.
References DGtal::LighterSternBrocot< TInteger, TQuotient, TMap >::Node::child(), and DGtal::LighterSternBrocot< TInteger, TQuotient, TMap >::Node::origin().
|
inline |
Definition at line 213 of file LighterSternBrocot.ih.
Referenced by DGtal::LighterSternBrocot< TInteger, TQuotient, TMap >::display().
|
inline |
Definition at line 397 of file LighterSternBrocot.ih.
|
inline |
other | any fraction. |
Definition at line 313 of file LighterSternBrocot.ih.
References operator==().
|
inline |
other | any fraction. |
Definition at line 322 of file LighterSternBrocot.ih.
References DGtal::LighterSternBrocot< TInteger, TQuotient, TMap >::Fraction::p(), and DGtal::LighterSternBrocot< TInteger, TQuotient, TMap >::Fraction::q().
|
inline |
Assignment
other | the object to clone. |
Definition at line 199 of file LighterSternBrocot.ih.
References DGtal::LighterSternBrocot< TInteger, TQuotient, TMap >::Fraction::myNode, and DGtal::LighterSternBrocot< TInteger, TQuotient, TMap >::Fraction::mySup1.
|
inline |
other | any fraction. |
Definition at line 300 of file LighterSternBrocot.ih.
References DGtal::LighterSternBrocot< TInteger, TQuotient, TMap >::Fraction::myNode, DGtal::LighterSternBrocot< TInteger, TQuotient, TMap >::Fraction::mySup1, DGtal::LighterSternBrocot< TInteger, TQuotient, TMap >::Node::p, and DGtal::LighterSternBrocot< TInteger, TQuotient, TMap >::Node::q.
|
inline |
other | any fraction. |
Definition at line 331 of file LighterSternBrocot.ih.
References DGtal::LighterSternBrocot< TInteger, TQuotient, TMap >::Fraction::p(), and DGtal::LighterSternBrocot< TInteger, TQuotient, TMap >::Fraction::q().
|
inlineprotected |
Definition at line 406 of file LighterSternBrocot.ih.
Referenced by DGtal::LighterSternBrocot< TInteger, TQuotient, TMap >::Fraction::getCFrac().
|
inline |
Definition at line 222 of file LighterSternBrocot.ih.
Referenced by DGtal::LighterSternBrocot< TInteger, TQuotient, TMap >::display(), DGtal::LighterSternBrocot< TInteger, TQuotient, TMap >::Fraction::operator<(), and DGtal::LighterSternBrocot< TInteger, TQuotient, TMap >::Fraction::operator>().
|
inline |
|
inline |
Definition at line 463 of file LighterSternBrocot.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 522 of file LighterSternBrocot.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 531 of file LighterSternBrocot.ih.
References DGtal::LighterSternBrocot< TInteger, TQuotient, TMap >::instance(), DGtal::LighterSternBrocot< TInteger, TQuotient, TMap >::Fraction::inverse(), DGtal::LighterSternBrocot< TInteger, TQuotient, TMap >::myOneOverZero, DGtal::LighterSternBrocot< TInteger, TQuotient, TMap >::oneOverZero(), DGtal::LighterSternBrocot< TInteger, TQuotient, TMap >::operator=(), and DGtal::LighterSternBrocot< TInteger, TQuotient, TMap >::zeroOverOne().
|
inline |
Definition at line 231 of file LighterSternBrocot.ih.
Referenced by DGtal::LighterSternBrocot< TInteger, TQuotient, TMap >::display(), DGtal::LighterSternBrocot< TInteger, TQuotient, TMap >::Fraction::operator<(), and DGtal::LighterSternBrocot< TInteger, TQuotient, TMap >::Fraction::operator>().
|
inline |
i | a positive integer smaller or equal to k()+2. |
Definition at line 494 of file LighterSternBrocot.ih.
References DGtal::LighterSternBrocot< TInteger, TQuotient, TMap >::Node::child(), DGtal::LighterSternBrocot< TInteger, TQuotient, TMap >::oneOverZero(), DGtal::LighterSternBrocot< TInteger, TQuotient, TMap >::Node::origin(), DGtal::LighterSternBrocot< TInteger, TQuotient, TMap >::Node::u, and DGtal::LighterSternBrocot< TInteger, TQuotient, TMap >::zeroOverOne().
|
inline |
Definition at line 372 of file LighterSternBrocot.ih.
References DGtal::LighterSternBrocot< TInteger, TQuotient, TMap >::Node::child(), DGtal::LighterSternBrocot< TInteger, TQuotient, TMap >::instance(), DGtal::LighterSternBrocot< TInteger, TQuotient, TMap >::myOneOverZero, DGtal::LighterSternBrocot< TInteger, TQuotient, TMap >::oneOverOne(), and DGtal::LighterSternBrocot< TInteger, TQuotient, TMap >::Node::origin().
|
inline |
Writes/Displays the fraction on an output stream.
out | the output stream where the object is written. |
Definition at line 684 of file LighterSternBrocot.ih.
|
inline |
Definition at line 290 of file LighterSternBrocot.h.
References DGtal::LighterSternBrocot< TInteger, TQuotient, TMap >::Node::k, and DGtal::LighterSternBrocot< TInteger, TQuotient, TMap >::Fraction::myNode.
|
inline |
Definition at line 240 of file LighterSternBrocot.ih.
References DGtal::LighterSternBrocot< TInteger, TQuotient, TMap >::instance(), DGtal::LighterSternBrocot< TInteger, TQuotient, TMap >::myOneOverZero, and DGtal::LighterSternBrocot< TInteger, TQuotient, TMap >::Node::u.
Referenced by DGtal::LighterSternBrocot< TInteger, TQuotient, TMap >::display(), and DGtal::LighterSternBrocot< 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 236 of file LighterSternBrocot.h.
Referenced by DGtal::LighterSternBrocot< TInteger, TQuotient, TMap >::Fraction::operator=(), DGtal::LighterSternBrocot< TInteger, TQuotient, TMap >::Fraction::operator==(), and DGtal::LighterSternBrocot< TInteger, TQuotient, TMap >::Fraction::trueK().
|
private |
When 'true', the fraction is greater or equal than 1/1 (to its right).
Definition at line 238 of file LighterSternBrocot.h.
Referenced by DGtal::LighterSternBrocot< TInteger, TQuotient, TMap >::Fraction::isSup1(), DGtal::LighterSternBrocot< TInteger, TQuotient, TMap >::Fraction::operator=(), and DGtal::LighterSternBrocot< TInteger, TQuotient, TMap >::Fraction::operator==().