DGtal  0.9.3beta
Data Structures | Public Types | Public Member Functions | Static Public Member Functions | Data Fields | Private Member Functions | Private Attributes | Static Private Attributes
DGtal::SternBrocot< TInteger, TQuotient > Class Template Reference

#include <DGtal/arithmetic/SternBrocot.h>

Collaboration diagram for DGtal::SternBrocot< TInteger, TQuotient >:
[legend]

Data Structures

class  Fraction
 
struct  Node
 

Public Types

typedef TInteger Integer
 
typedef TQuotient Quotient
 
typedef SternBrocot< Integer, QuotientSelf
 

Public Member Functions

 BOOST_CONCEPT_ASSERT ((concepts::CInteger< Integer >))
 
 ~SternBrocot ()
 
bool isValid () const
 

Static Public Member Functions

static SternBrocotinstance ()
 
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)
 
SternBrocotoperator= (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

NodemyZeroOverOne
 
NodemyOneOverZero
 
NodemyOneOverOne
 

Static Private Attributes

static SternBrocotsingleton = 0
 

Detailed Description

template<typename TInteger, typename TQuotient = int32_t>
class DGtal::SternBrocot< TInteger, TQuotient >

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.

Template Parameters
TIntegerthe integral type chosen for the fractions.
TQuotientthe 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 77 of file SternBrocot.h.

Member Typedef Documentation

template<typename TInteger, typename TQuotient = int32_t>
typedef TInteger DGtal::SternBrocot< TInteger, TQuotient >::Integer

Definition at line 80 of file SternBrocot.h.

template<typename TInteger, typename TQuotient = int32_t>
typedef TQuotient DGtal::SternBrocot< TInteger, TQuotient >::Quotient

Definition at line 81 of file SternBrocot.h.

template<typename TInteger, typename TQuotient = int32_t>
typedef SternBrocot<Integer,Quotient> DGtal::SternBrocot< TInteger, TQuotient >::Self

Definition at line 82 of file SternBrocot.h.

Constructor & Destructor Documentation

template<typename TInteger, typename TQuotient = int32_t>
DGtal::SternBrocot< TInteger, TQuotient >::~SternBrocot ( )

Destructor.

template<typename TInteger, typename TQuotient = int32_t>
DGtal::SternBrocot< TInteger, TQuotient >::SternBrocot ( )
private

Constructor. Hidden since singleton class.

template<typename TInteger, typename TQuotient = int32_t>
DGtal::SternBrocot< TInteger, TQuotient >::SternBrocot ( const SternBrocot< TInteger, TQuotient > &  other)
private

Copy constructor.

Parameters
otherthe object to clone. Forbidden by default.

Member Function Documentation

template<typename TInteger, typename TQuotient = int32_t>
DGtal::SternBrocot< TInteger, TQuotient >::BOOST_CONCEPT_ASSERT ( (concepts::CInteger< Integer >)  )
template<typename TInteger, typename TQuotient = int32_t>
static void DGtal::SternBrocot< TInteger, TQuotient >::display ( std::ostream &  out,
const Fraction f 
)
static

Writes/Displays the fraction on an output stream.

Parameters
outthe output stream where the object is written.
fthe fraction to display.
template<typename TInteger, typename TQuotient = int32_t>
static Fraction DGtal::SternBrocot< TInteger, TQuotient >::fraction ( Integer  p,
Integer  q,
Fraction  ancestor = zeroOverOne() 
)
static

Any fraction p/q. Complexity is in \( \sum_i u_i \), where u_i are the partial quotients of p/q.

Parameters
pthe numerator (>=0)
qthe denominator (>=0)
ancestor(optional) any ancestor of p/q in the tree (for speed-up).
Returns
the corresponding fraction in the Stern-Brocot tree.

NB: Complexity is bounded by \( 2 \sum_i u_i \), where u_i are the partial quotients of p/q.

template<typename TInteger, typename TQuotient = int32_t>
static SternBrocot& DGtal::SternBrocot< TInteger, TQuotient >::instance ( )
static
Returns
the (only) instance of SternBrocot.
template<typename TInteger, typename TQuotient = int32_t>
bool DGtal::SternBrocot< TInteger, TQuotient >::isValid ( ) const

Checks the validity/consistency of the object.

Returns
'true' if the object is valid, 'false' otherwise.
template<typename TInteger, typename TQuotient = int32_t>
static Fraction DGtal::SternBrocot< TInteger, TQuotient >::oneOverZero ( )
static

The fraction 1/0

template<typename TInteger, typename TQuotient = int32_t>
SternBrocot& DGtal::SternBrocot< TInteger, TQuotient >::operator= ( const SternBrocot< TInteger, TQuotient > &  other)
private

Assignment.

Parameters
otherthe object to copy.
Returns
a reference on 'this'. Forbidden by default.

Definition at line 54 of file SternBrocot.cpp.

Definition at line 58 of file SternBrocot.cpp.

Definition at line 62 of file SternBrocot.cpp.

template<typename TInteger, typename TQuotient = int32_t>
static Fraction DGtal::SternBrocot< TInteger, TQuotient >::zeroOverOne ( )
static

The fraction 0/1

Field Documentation

template<typename TInteger, typename TQuotient = int32_t>
Node* DGtal::SternBrocot< TInteger, TQuotient >::myOneOverOne
private

Definition at line 472 of file SternBrocot.h.

template<typename TInteger, typename TQuotient = int32_t>
Node* DGtal::SternBrocot< TInteger, TQuotient >::myOneOverZero
private

Definition at line 471 of file SternBrocot.h.

template<typename TInteger, typename TQuotient = int32_t>
Node* DGtal::SternBrocot< TInteger, TQuotient >::myZeroOverOne
private

Definition at line 470 of file SternBrocot.h.

template<typename TInteger, typename TQuotient = int32_t>
Quotient DGtal::SternBrocot< TInteger, TQuotient >::nbFractions

The total number of fractions in the current tree.

Definition at line 461 of file SternBrocot.h.

template<typename TInteger, typename TQuotient = int32_t>
DGtal::SternBrocot< TInteger, TQuotient > * DGtal::SternBrocot< TInteger, TQuotient >::singleton = 0
staticprivate

Singleton class.

Definition at line 468 of file SternBrocot.h.


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