From fff0941de18d166b76ce8a6fac25c7d6c49d7eb7 Mon Sep 17 00:00:00 2001 From: Eric Berberich Date: Tue, 5 Aug 2008 10:12:00 +0000 Subject: [PATCH] we still require this file for 3d --- .../Best_approximation_cache.h | 122 ++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 Algebraic_kernel_d/include/CGAL/Algebraic_curve_kernel_2/Bitstream_descartes_at_x/Best_approximation_cache.h diff --git a/Algebraic_kernel_d/include/CGAL/Algebraic_curve_kernel_2/Bitstream_descartes_at_x/Best_approximation_cache.h b/Algebraic_kernel_d/include/CGAL/Algebraic_curve_kernel_2/Bitstream_descartes_at_x/Best_approximation_cache.h new file mode 100644 index 00000000000..0ed5eb74e5f --- /dev/null +++ b/Algebraic_kernel_d/include/CGAL/Algebraic_curve_kernel_2/Bitstream_descartes_at_x/Best_approximation_cache.h @@ -0,0 +1,122 @@ +// TODO: Add licence +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL:$ +// $Id$ +// +// +// Author(s) : Michael Kerber +// +// ============================================================================ + +#ifndef CGAL_BEST_APPROXIMATION_CACHE +#define CGAL_BEST_APPROXIMATION_CACHE 1 + + +#include +#include +#include +#include + +CGAL_BEGIN_NAMESPACE + + + namespace CGALi { + + /*! + * \brief Stores computed approximations for coefficients. + * + * During the execution of the Bitstream Descartes method, approximations + * of the coefficients are computed independently by different branches of + * the Descartes tree. To avoid computing them several times, the best + * konwn approximation for a special coefficient is stored in a \c std::map + * structure. The data contains the used precision and the integer that + * represents the coefficient for this precision, according to the + * \c CGAL::CGALi::Bitstream_descartes_rndl_tree_traits definition. + */ + template + class Best_approximation_cache + : public ::CGAL::Handle_with_policy > > { + + public: + + //! The Coefficient type + typedef Coefficient_ Coefficient; + + //! The integer type + typedef Integer_ Integer; + + typedef std::pair Data_pair; + + typedef std::map Map; + + typedef ::CGAL::Handle_with_policy Base; + + typedef Best_approximation_cache Self; + + //! Default constructor + Best_approximation_cache() { + } + + //! Copy constructor + Best_approximation_cache(const Self& s) + : Base(static_cast(s)) + {} + + /*! + * \brief Checks whether the coefficient \c c already has already been + * approximated. + */ + bool approximation_exists(Coefficient c) const { + typename Map::const_iterator it = this->ptr()->find(c); + return it!=this->ptr()->end(); + } + + /*! + * \brief The best approximation known for the coefficient c + * is returned. + * + * It is necessary to check whether an approximation of c exists + * using the \c approximation_exists method beforehand! + */ + void get_best_approximation(Coefficient c,long& prec, Integer& val) const{ + typename Map::const_iterator it = this->ptr()->find(c); + CGAL_assertion(it!=this->ptr()->end()); + prec = it->second.first; + val = it->second.second; + } + + /*! + * \brief Updates the approximation memory + * + * If an approximation for c is known, this method can be used + * to store it for later usage. The update is only performed if the + * precision is indeed higher than the current precision in the map. + */ + void update_approximation(Coefficient c,long prec, const Integer& val) { + typename Map::iterator it = this->ptr()->find(c); + if(it!=this->ptr()->end()) { + if(it->second.first >= prec) { + return; + } + else { + Data_pair better_pair = std::make_pair(prec,val); + it->second=better_pair; + } + } + else { + Data_pair new_pair = std::make_pair(prec,val); + this->ptr()->operator[](c)=new_pair; + } + + } + }; + + + }// namespace CGALi + +CGAL_END_NAMESPACE + +#endif // AcX_BEST_APPROXIMATION_CACHE