DGtal
0.6.devel
|
#include <SternBrocot.h>
Data Structures | |
class | Fraction |
This fraction is a model of CPositiveIrreducibleFraction. More... | |
struct | Node |
Public Types | |
typedef TInteger | Integer |
typedef TQuotient | Quotient |
typedef SternBrocot< Integer, Quotient > | Self |
Public Member Functions | |
BOOST_CONCEPT_ASSERT ((CInteger< Integer >)) | |
BOOST_CONCEPT_ASSERT ((CSignedInteger< Quotient >)) | |
~SternBrocot () | |
bool | isValid () const |
Static Public Member Functions | |
static SternBrocot & | instance () |
static Fraction | zeroOverOne () |
static Fraction | oneOverZero () |
static Fraction | fraction (Integer p, Integer q, Fraction ancestor=zeroOverOne()) |
static void | display (std::ostream &out, const Fraction &f) |
Data Fields | |
Quotient | nbFractions |
Private Member Functions | |
SternBrocot () | |
SternBrocot (const SternBrocot &other) | |
SternBrocot & | operator= (const SternBrocot &other) |
template<> | |
SternBrocot< DGtal::int32_t, DGtal::int32_t > * | singleton |
template<> | |
SternBrocot< DGtal::int64_t, DGtal::int32_t > * | singleton |
template<> | |
SternBrocot< DGtal::int64_t, DGtal::int64_t > * | singleton |
Private Attributes | |
Node * | myZeroOverOne |
Node * | myOneOverZero |
Node * | myOneOverOne |
Static Private Attributes | |
static SternBrocot * | singleton = 0 |
Aim: The Stern-Brocot tree is the tree of irreducible fractions. This class allows to construct it progressively and to navigate within fractions in O(1) time for most operations. It is well known that the structure of this tree is a coding of the continued fraction representation of fractions.
Description of template class 'SternBrocot'
This class is not to be instantiated, since it is useless to duplicate it. Use static method SternBrocot::fraction to obtain your fractions.
TInteger | the integral type chosen for the fractions. |
TQuotient | the integral type chosen for the quotients/coefficients or depth (may be "smaller" than TInteger, since they are generally much smaller than the fraction itself). |
Definition at line 78 of file SternBrocot.h.
typedef TInteger DGtal::SternBrocot< TInteger, TQuotient >::Integer |
Definition at line 81 of file SternBrocot.h.
typedef TQuotient DGtal::SternBrocot< TInteger, TQuotient >::Quotient |
Definition at line 82 of file SternBrocot.h.
typedef SternBrocot<Integer,Quotient> DGtal::SternBrocot< TInteger, TQuotient >::Self |
Definition at line 83 of file SternBrocot.h.
|
inline |
Destructor.
Definition at line 533 of file SternBrocot.ih.
References DGtal::SternBrocot< TInteger, TQuotient >::myOneOverOne, DGtal::SternBrocot< TInteger, TQuotient >::myOneOverZero, and DGtal::SternBrocot< TInteger, TQuotient >::myZeroOverOne.
|
inlineprivate |
Constructor. Hidden since singleton class.
Definition at line 542 of file SternBrocot.ih.
References DGtal::SternBrocot< TInteger, TQuotient >::Node::ascendantLeft, DGtal::SternBrocot< TInteger, TQuotient >::Node::descendantLeft, DGtal::SternBrocot< TInteger, TQuotient >::Node::descendantRight, DGtal::SternBrocot< TInteger, TQuotient >::Node::inverse, DGtal::SternBrocot< TInteger, TQuotient >::myOneOverOne, DGtal::SternBrocot< TInteger, TQuotient >::myOneOverZero, DGtal::SternBrocot< TInteger, TQuotient >::myZeroOverOne, and DGtal::SternBrocot< TInteger, TQuotient >::nbFractions.
Referenced by DGtal::SternBrocot< TInteger, TQuotient >::instance().
|
private |
Copy constructor.
other | the object to clone. Forbidden by default. |
DGtal::SternBrocot< TInteger, TQuotient >::BOOST_CONCEPT_ASSERT | ( | (CInteger< Integer >) | ) |
DGtal::SternBrocot< TInteger, TQuotient >::BOOST_CONCEPT_ASSERT | ( | (CSignedInteger< Quotient >) | ) |
|
inlinestatic |
Writes/Displays the fraction on an output stream.
out | the output stream where the object is written. |
f | the fraction to display. |
Writes/Displays the object on an output stream.
out | the output stream where the object is written. |
Definition at line 609 of file SternBrocot.ih.
References DGtal::SternBrocot< TInteger, TQuotient >::Fraction::getCFrac(), DGtal::SternBrocot< TInteger, TQuotient >::Fraction::k(), DGtal::SternBrocot< TInteger, TQuotient >::Fraction::null(), DGtal::SternBrocot< TInteger, TQuotient >::Fraction::p(), DGtal::SternBrocot< TInteger, TQuotient >::Fraction::q(), and DGtal::SternBrocot< TInteger, TQuotient >::Fraction::u().
|
inlinestatic |
Any fraction p/q. Complexity is in \( \sum_i u_i \), where u_i are the partial quotients of p/q.
p | the numerator (>=0) |
q | the denominator (>=0) |
ancestor | (optional) any ancestor of p/q in the tree (for speed-up). |
NB: Complexity is bounded by \( 2 \sum_i u_i \), where u_i are the partial quotients of p/q.
Definition at line 652 of file SternBrocot.ih.
References DGtal::SternBrocot< TInteger, TQuotient >::Fraction::equals(), DGtal::IntegerComputer< TInteger >::gcd(), DGtal::SternBrocot< TInteger, TQuotient >::Fraction::left(), DGtal::SternBrocot< TInteger, TQuotient >::Fraction::lessThan(), DGtal::SternBrocot< TInteger, TQuotient >::oneOverZero(), DGtal::SternBrocot< TInteger, TQuotient >::Fraction::p(), DGtal::SternBrocot< TInteger, TQuotient >::Fraction::q(), and DGtal::SternBrocot< TInteger, TQuotient >::Fraction::right().
|
inlinestatic |
Definition at line 574 of file SternBrocot.ih.
References DGtal::SternBrocot< TInteger, TQuotient >::singleton(), and DGtal::SternBrocot< TInteger, TQuotient >::SternBrocot().
Referenced by DGtal::SternBrocot< TInteger, TQuotient >::Fraction::left(), DGtal::SternBrocot< TInteger, TQuotient >::oneOverZero(), and DGtal::SternBrocot< TInteger, TQuotient >::zeroOverOne().
|
inline |
Checks the validity/consistency of the object.
Definition at line 640 of file SternBrocot.ih.
|
inlinestatic |
The fraction 1/0
Definition at line 594 of file SternBrocot.ih.
References DGtal::SternBrocot< TInteger, TQuotient >::instance(), and DGtal::SternBrocot< TInteger, TQuotient >::myOneOverZero.
Referenced by DGtal::SternBrocot< TInteger, TQuotient >::fraction(), and DGtal::SternBrocot< TInteger, TQuotient >::Fraction::pushBack().
|
private |
Assignment.
other | the object to copy. |
Referenced by DGtal::SternBrocot< TInteger, TQuotient >::Fraction::Fraction(), and DGtal::SternBrocot< TInteger, TQuotient >::Fraction::pushBack().
|
private |
Definition at line 57 of file SternBrocot.cpp.
Referenced by DGtal::SternBrocot< TInteger, TQuotient >::instance().
|
private |
Definition at line 61 of file SternBrocot.cpp.
|
private |
Definition at line 65 of file SternBrocot.cpp.
|
inlinestatic |
The fraction 0/1
Definition at line 586 of file SternBrocot.ih.
References DGtal::SternBrocot< TInteger, TQuotient >::instance(), and DGtal::SternBrocot< TInteger, TQuotient >::myZeroOverOne.
Referenced by DGtal::SternBrocot< TInteger, TQuotient >::Fraction::pushBack().
|
private |
Definition at line 456 of file SternBrocot.h.
Referenced by DGtal::SternBrocot< TInteger, TQuotient >::SternBrocot(), and DGtal::SternBrocot< TInteger, TQuotient >::~SternBrocot().
|
private |
Definition at line 455 of file SternBrocot.h.
Referenced by DGtal::SternBrocot< TInteger, TQuotient >::oneOverZero(), DGtal::SternBrocot< TInteger, TQuotient >::SternBrocot(), and DGtal::SternBrocot< TInteger, TQuotient >::~SternBrocot().
|
private |
Definition at line 454 of file SternBrocot.h.
Referenced by DGtal::SternBrocot< TInteger, TQuotient >::SternBrocot(), DGtal::SternBrocot< TInteger, TQuotient >::zeroOverOne(), and DGtal::SternBrocot< TInteger, TQuotient >::~SternBrocot().
Quotient DGtal::SternBrocot< TInteger, TQuotient >::nbFractions |
The total number of fractions in the current tree.
Definition at line 445 of file SternBrocot.h.
Referenced by DGtal::SternBrocot< TInteger, TQuotient >::Fraction::left(), and DGtal::SternBrocot< TInteger, TQuotient >::SternBrocot().
|
staticprivate |
Singleton class.
Definition at line 452 of file SternBrocot.h.