URL:
https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2008-03-19 Michel Pellegrin <pellegrin(a)lrde.epita.fr>
Fix some mistakes, Add.
* sandbox/pellegrin/set/core/line2d.hh,
* sandbox/pellegrin/set/core/p_array.hh,
* sandbox/pellegrin/set/core/p_bgraph.hh,
* sandbox/pellegrin/set/core/p_graph.hh,
* sandbox/pellegrin/set/core/p_line_graph.hh,
* sandbox/pellegrin/set/core/p_priority_queue.hh,
* sandbox/pellegrin/set/core/p_priority_queue_fast.hh,
* sandbox/pellegrin/set/core/p_priority_queue_fast_with_array.hh,
* sandbox/pellegrin/set/core/p_queue.hh,
* sandbox/pellegrin/set/core/p_queue_fast.hh,
* sandbox/pellegrin/set/core/p_set.hh,
* sandbox/pellegrin/set/core/pset_if.hh: traits are up-to-date
(or not, i have to check it with theo) and add the fwd decls.
* sandbox/pellegrin/set/core/p_run.hh: New.
* sandbox/pellegrin/set/core/p_runs.hh: New.
* sandbox/pellegrin/set/core/runs_psite.hh: Remove (not a point_set).
---
line2d.hh | 8
p_array.hh | 6
p_bgraph.hh | 18 -
p_graph.hh | 6
p_line_graph.hh | 15
p_priority_queue.hh | 8
p_priority_queue_fast.hh | 8
p_priority_queue_fast_with_array.hh | 10
p_queue.hh | 6
p_queue_fast.hh | 6
p_run.hh | 250 ++++++++++++++++
p_runs.hh | 541 ++++++++++++++++++++++++++++++++++++
p_set.hh | 6
pset_if.hh | 7
14 files changed, 860 insertions(+), 35 deletions(-)
Index: trunk/milena/sandbox/pellegrin/set/core/runs_psite.hh (deleted)
===================================================================
Index: trunk/milena/sandbox/pellegrin/set/core/p_priority_queue_fast.hh
===================================================================
--- trunk/milena/sandbox/pellegrin/set/core/p_priority_queue_fast.hh (revision 1789)
+++ trunk/milena/sandbox/pellegrin/set/core/p_priority_queue_fast.hh (revision 1790)
@@ -44,19 +44,23 @@
# include <mln/core/p_array_piter.hh>
# include <mln/accu/bbox.hh>
# include <mln/core/p_queue_fast.hh>
+# include <mln/trait/point_set.hh>
+
namespace mln
{
// Fwd decls.
+ template <typename P, typename T> struct p_priority_queue_fast;
template <typename P> struct p_array_fwd_piter_;
template <typename P> struct p_array_bkd_piter_;
namespace trait
{
- template <typename P>
- struct point_set_<line2d> : public default_point_set_<P>
+ template <typename P, typename T>
+ struct point_set_< p_priority_queue_fast<P, T> >
+ : public default_point_set_< p_priority_queue_fast<P, T> >
{
typedef trait::point_set::arity::unique arity;
typedef trait::point_set::has_speed::fast has_speed;
Index: trunk/milena/sandbox/pellegrin/set/core/p_bgraph.hh
===================================================================
--- trunk/milena/sandbox/pellegrin/set/core/p_bgraph.hh (revision 1789)
+++ trunk/milena/sandbox/pellegrin/set/core/p_bgraph.hh (revision 1790)
@@ -25,8 +25,11 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_CORE_BGRAPH_P_HH
-# define MLN_CORE_BGRAPH_P_HH
+#ifndef MLN_CORE_P_BGRAPH_HH
+# define MLN_CORE_P_BGRAPH_HH
+
+/// \file mln/core/p_bgraph.hh
+/// \brief Definition of a point set based on a boost graph.
# include <utility>
@@ -36,22 +39,21 @@
# include <mln/util/internal/boost_graph.hh>
# include <mln/core/bgraph_psite.hh>
# include <mln/core/p_bgraph_piter.hh>
+# include <mln/trait/point_set.hh>
-
-/// \file mln/core/p_bgraph.hh
-/// \brief Definition of a point set based on a boost graph.
-
namespace mln
{
+ // Fwd decls.
+ template <typename P> struct p_bgraph;
template<typename P> class p_bgraph_piter_;
namespace trait
{
template <typename P>
- struct point_set_<line2d> : public default_point_set_<P>
+ struct point_set_< p_bgraph<P> > : public default_point_set_<
p_bgraph<P> >
{
typedef trait::point_set::arity::unique arity;
typedef trait::point_set::has_speed::fast has_speed;
@@ -229,4 +231,4 @@
} // end of mln
-#endif // MLN_CORE_BGRAPH_P_HH
+#endif // MLN_CORE_P_BGRAPH_HH
Index: trunk/milena/sandbox/pellegrin/set/core/p_run.hh
===================================================================
--- trunk/milena/sandbox/pellegrin/set/core/p_run.hh (revision 0)
+++ trunk/milena/sandbox/pellegrin/set/core/p_run.hh (revision 1790)
@@ -0,0 +1,250 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_CORE_P_RUN_HH
+# define MLN_CORE_P_RUN_HH
+
+/*! \file mln/core/p_run.hh
+ *
+ * \brief Definition of a point set class based on std::set.
+ */
+
+# include <mln/core/internal/point_set_base.hh>
+# include <mln/core/internal/set_of.hh>
+# include <mln/accu/bbox.hh>
+# include <mln/trait/point_set.hh>
+
+
+namespace mln
+{
+
+ // Fwd decls.
+ template <typename P> struct p_run;
+ template <typename P> struct p_run_fwd_piter_;
+ template <typename P> struct p_run_bkd_piter_;
+
+ namespace trait
+ {
+
+ template <typename P>
+ struct point_set_< p_run<P> > : public default_point_set_<
p_run<P> >
+ {
+ typedef trait::point_set::arity::unique arity;
+ typedef trait::point_set::has_speed::fast has_speed;
+ }
+
+ }
+
+ /*! \brief Point set class in run.
+ *
+ * This is a mathematical set of points (not a multi-set). The
+ * parameter \p P shall be a Point type.
+ *
+ * \todo Test if \p P being a Point_Site is ok.
+ */
+ template <typename P>
+ class p_run : public internal::point_set_base_< P, p_run<P> >
+ {
+ public:
+
+ /// Forward Point_Iterator associated type.
+ typedef p_run_fwd_piter_<P> fwd_piter;
+
+ /// Backward Point_Iterator associated type.
+ typedef p_run_bkd_piter_<P> bkd_piter;
+
+ /// Constructor without argument.
+ p_run();
+
+ /// Constructor.
+ p_run(const P& start, std::size_t len);
+
+ /// Set the starting point.
+ void set_run(const P& start, std::size_t len);
+
+ /// Test is \p p belongs to this point set.
+ bool has(const P& p) const;
+
+ /// Give the number of points.
+ std::size_t npoints() const;
+
+ /// Give the length of the run.
+ std::size_t length() const;
+
+ /// Return the \p i-th point.
+ P operator[](unsigned i) const;
+
+ /// Return the first point.
+ const P& first() const;
+
+ /// Give the exact bounding box.
+ const box_<mln_point(P)>& bbox() const;
+
+ /// Set a relation order to p_run.
+ bool operator<(const p_run<P>& rhs) const;
+
+ protected:
+
+ accu::bbox<P> bb_;
+ // FIXME: Add invariant bb_.is_valid() <=> npoints() != 0
+
+ /// The first point of the run.
+ P p_;
+
+ /// The length of the run.
+ std::size_t len_;
+
+ /// For internal use.
+ bool is_valid_;
+ };
+
+ template <typename P>
+ std::ostream& operator<<(std::ostream& out, const p_run<P>&
pr)
+ {
+ out << "Run: (" << pr.first() << ", " <<
pr.length() << ")";
+ return out;
+ }
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename P>
+ inline
+ p_run<P>::p_run()
+ {
+ is_valid_ = false;
+ }
+
+ template <typename P>
+ inline
+ p_run<P>::p_run(const P& start, std::size_t len)
+ : p_(start),
+ len_(len)
+ {
+ mln_precondition(len != 0);
+ P p = start;
+ bb_.init();
+ bb_.take(p);
+ p[P::dim - 1] += len - 1;
+ bb_.take(p);
+ is_valid_ = true;
+ }
+
+ template <typename P>
+ inline
+ void
+ p_run<P>::set_run(const P& start, std::size_t len)
+ {
+ mln_precondition(len != 0);
+ p_ = start;
+ len_ = len;
+ P p = start;
+ bb_.init();
+ bb_.take(p);
+ p[P::dim - 1] += len - 1;
+ bb_.take(p);
+ is_valid_ = true;
+ }
+
+ template <typename P>
+ inline
+ bool
+ p_run<P>::has(const P& p) const
+ {
+ mln_precondition(is_valid_);
+ bool res = true;
+ for (int i = P::dim - 2; i >= 0; --i)
+ if (!(res = (res && p[i] == p_[i])))
+ return false;
+ return (p[P::dim - 1] >= p_[P::dim - 1]
+ && p[P::dim - 1] < p_[P::dim - 1] + (signed)len_);
+ }
+
+ template <typename P>
+ inline
+ std::size_t
+ p_run<P>::npoints() const
+ {
+ mln_precondition(is_valid_);
+ return len_;
+ }
+
+ template <typename P>
+ inline
+ std::size_t
+ p_run<P>::length() const
+ {
+ mln_precondition(is_valid_);
+ return len_;
+ }
+
+ template <typename P>
+ inline
+ P
+ p_run<P>::operator[](unsigned i) const
+ {
+ mln_precondition(is_valid_);
+ mln_precondition(i < npoints());
+ P p = p_;
+ p[P::dim - 1] += i;
+ return p;
+ }
+
+ template <typename P>
+ inline
+ const P&
+ p_run<P>::first() const
+ {
+ return p_;
+ }
+
+ template <typename P>
+ inline
+ const box_<mln_point(P)>&
+ p_run<P>::bbox() const
+ {
+ mln_precondition(is_valid_);
+ mln_precondition(npoints() != 0);
+ return bb_.to_result();
+ }
+
+ template <typename P>
+ inline
+ bool
+ p_run<P>::operator<(const p_run<P>& rhs) const
+ {
+ return (this->p_ < rhs.p_)
+ || (this->p_ == rhs.p_ && this->len_ < rhs.len_);
+ }
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+# include <mln/core/p_run_piter.hh>
+
+#endif // ! MLN_CORE_P_RUN_HH
Index: trunk/milena/sandbox/pellegrin/set/core/p_line_graph.hh
===================================================================
--- trunk/milena/sandbox/pellegrin/set/core/p_line_graph.hh (revision 1789)
+++ trunk/milena/sandbox/pellegrin/set/core/p_line_graph.hh (revision 1790)
@@ -25,8 +25,8 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_CORE_LINE_GRAPH_P_HH
-# define MLN_CORE_LINE_GRAPH_P_HH
+#ifndef MLN_CORE_P_LINE_GRAPH_HH
+# define MLN_CORE_P_LINE_GRAPH_HH
# include <mln/core/concept/point_site.hh>
# include <mln/core/internal/point_set_base.hh>
@@ -35,11 +35,12 @@
# include <mln/core/line_graph_psite.hh>
# include <mln/core/p_line_graph_piter.hh>
# include <mln/core/point_pair.hh>
+# include <mln/trait/point_set.hh>
+
/* FIXME: This class shares a lot with p_graph. Factor as much as
possible. */
-
/// \file mln/core/p_line_graph.hh
/// \brief Definition of a point set based on line graph.
@@ -54,14 +55,15 @@
// Nothing.
};
-
+ // Fwd decl.
+ template <typename P> struct p_line_graph;
template<typename P> class p_line_graph_piter_;
namespace trait
{
template <typename P>
- struct point_set_<line2d> : public default_point_set_<P>
+ struct point_set_< p_line_graph<P> > : public default_point_set_<
p_line_graph<P> >
{
typedef trait::point_set::arity::unique arity;
typedef trait::point_set::has_speed::fast has_speed;
@@ -172,5 +174,4 @@
} // end of mln
-
-#endif // MLN_CORE_P_GRAPH_HH
+#endif // MLN_CORE_P_LINE_GRAPH_HH
Index: trunk/milena/sandbox/pellegrin/set/core/pset_if.hh
===================================================================
--- trunk/milena/sandbox/pellegrin/set/core/pset_if.hh (revision 1789)
+++ trunk/milena/sandbox/pellegrin/set/core/pset_if.hh (revision 1790)
@@ -35,6 +35,7 @@
# include <mln/core/internal/point_set_base.hh>
# include <mln/core/concept/function.hh>
+# include <mln/trait/point_set.hh>
namespace mln
@@ -48,11 +49,11 @@
namespace trait
{
- template <typename P>
- struct point_set_< pset_if<> > : public default_point_set_<P>
+ template <typename S, typename F>
+ struct point_set_< pset_if<S, F> > : public default_point_set_<
pset_if<S, F> >
{
typedef trait::point_set::arity::unique arity;
- typedef trait::point_set::has_speed::fast has_speed;
+ typedef trait::point_set::has_speed::slow has_speed;
}
}
Index: trunk/milena/sandbox/pellegrin/set/core/p_array.hh
===================================================================
--- trunk/milena/sandbox/pellegrin/set/core/p_array.hh (revision 1789)
+++ trunk/milena/sandbox/pellegrin/set/core/p_array.hh (revision 1790)
@@ -37,12 +37,14 @@
# include <mln/core/internal/point_set_base.hh>
# include <mln/accu/bbox.hh>
+# include <mln/trait/point_set.hh>
namespace mln
{
// Fwd decls.
+ template <typename P> struct p_array;
template <typename P> struct p_array_fwd_piter_;
template <typename P> struct p_array_bkd_piter_;
@@ -50,9 +52,9 @@
{
template <typename P>
- struct point_set_< p_array<P> > : public default_point_set_<P>
+ struct point_set_< p_array<P> > : public default_point_set_<
p_array<P> >
{
- typedef trait::point_set::arity::unique arity;
+ typedef trait::point_set::arity::multiple arity;
typedef trait::point_set::has_speed::fast has_speed;
}
Index: trunk/milena/sandbox/pellegrin/set/core/p_queue.hh
===================================================================
--- trunk/milena/sandbox/pellegrin/set/core/p_queue.hh (revision 1789)
+++ trunk/milena/sandbox/pellegrin/set/core/p_queue.hh (revision 1790)
@@ -41,12 +41,14 @@
# include <mln/core/internal/point_set_base.hh>
# include <mln/core/p_array_piter.hh>
# include <mln/accu/bbox.hh>
+# include <mln/trait/point_set.hh>
namespace mln
{
// Fwd decls.
+ template <typename P> struct p_queue;
template <typename P> struct p_array_fwd_piter_;
template <typename P> struct p_array_bkd_piter_;
@@ -54,10 +56,10 @@
{
template <typename P>
- struct point_set_<line2d> : public default_point_set_<P>
+ struct point_set_< p_queue<P> > : public default_point_set_<
p_queue<P> >
{
typedef trait::point_set::arity::unique arity;
- typedef trait::point_set::has_speed::fast has_speed;
+ typedef trait::point_set::has_speed::slow has_speed;
}
}
Index: trunk/milena/sandbox/pellegrin/set/core/p_priority_queue.hh
===================================================================
--- trunk/milena/sandbox/pellegrin/set/core/p_priority_queue.hh (revision 1789)
+++ trunk/milena/sandbox/pellegrin/set/core/p_priority_queue.hh (revision 1790)
@@ -44,11 +44,14 @@
# include <mln/core/p_array_piter.hh>
# include <mln/accu/bbox.hh>
# include <mln/core/p_queue.hh>
+# include <mln/trait/point_set.hh>
+
namespace mln
{
// Fwd decls.
+ template <typename P, typename T> struct p_priority_queue;
template <typename P> struct p_array_fwd_piter_;
template <typename P> struct p_array_bkd_piter_;
@@ -56,10 +59,11 @@
{
template <typename P>
- struct point_set_<line2d> : public default_point_set_<P>
+ struct point_set_< p_priority_queue<P> >
+ : public default_point_set_< p_priority_queue<P> >
{
typedef trait::point_set::arity::unique arity;
- typedef trait::point_set::has_speed::fast has_speed;
+ typedef trait::point_set::has_speed::slow has_speed;
}
}
Index: trunk/milena/sandbox/pellegrin/set/core/p_runs.hh
===================================================================
--- trunk/milena/sandbox/pellegrin/set/core/p_runs.hh (revision 0)
+++ trunk/milena/sandbox/pellegrin/set/core/p_runs.hh (revision 1790)
@@ -0,0 +1,541 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_CORE_P_RUNS_HH
+# define MLN_CORE_P_RUNS_HH
+
+/*! \file mln/core/p_runs.hh
+ *
+ * \brief Definition of mln::internal::p_runs_ class and its iterators
+ * (for internal use only).
+ */
+
+# include <utility>
+
+# include <mln/core/internal/point_set_base.hh>
+# include <mln/core/internal/point_iterator_base.hh>
+# include <mln/core/runs_psite.hh>
+# include <mln/core/p_run.hh>
+# include <mln/accu/bbox.hh>
+# include <mln/util/lazy_set.hh>
+# include <mln/trait/point_set.hh>
+
+
+namespace mln
+{
+
+ // Forward declaration
+ template <typename P> struct p_runs;
+ template <typename P> struct p_runs_fwd_piter_;
+ template <typename P> struct p_runs_bkd_piter_;
+
+ namespace trait
+ {
+
+ template <typename P>
+ struct point_set_< p_runs<P> > : public default_point_set_<
p_runs<P> >
+ {
+ typedef trait::point_set::arity::multiple arity;
+ typedef trait::point_set::has_speed::fast has_speed;
+ }
+
+ }
+
+ /*! \brief p_runs_ class represent a point set used in run_image_ class.
+ *
+ * Parameter \c P is the type of the image point.
+ */
+ template <typename P>
+ class p_runs_ : public internal::point_set_base_< runs_psite<P>,
p_runs_<P> >
+ {
+ public:
+
+// typedef util::lazy_set_<p_run<P> > container;
+ typedef p_runs_fwd_piter_<P> fwd_piter;
+ typedef p_runs_bkd_piter_<P> bkd_piter;
+
+ /// Constructor without arguments.
+ p_runs_();
+
+ /// Test is \p p belongs to this point set.
+ bool has(const runs_psite<P>& ps) const;
+
+ /// Give the exact bounding box.
+ const box_<P>& bbox() const;
+
+ /// Give the number of points.
+ typename std::size_t npoints() const;
+
+ /// Insert a range, start at point \p p wit len \p len.
+ void insert(const p_run<P>& pr);
+
+ /// Return the number of runs.
+ unsigned nruns() const;
+
+ /// Return the len of the range starting at point \p p.
+ unsigned range_len_(const P& p) const;
+
+ /// Return the i-th run of the list of runs
+ const p_run<P>& operator[](unsigned i) const;
+
+ /// Return the size of the data in memory.
+ unsigned size_mem() const;
+
+ /// Finalize the lazy_set (internal use)
+ void finalize();
+
+// /// Return the container of the pset (internal use only).
+// const container& con() const;
+
+ protected:
+
+ /// Number of points.
+ typename std::size_t npoints_;
+
+ /// Points container
+ util::lazy_set_<p_run<P> > con_;
+
+ /// Exact bounding box.
+ accu::bbox<P> fb_;
+ };
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename P>
+ inline
+ p_runs_<P>::p_runs_() :
+ npoints_(0)
+ {
+ }
+
+ template <typename P>
+ inline
+ bool
+ p_runs_<P>::has(const runs_psite<P>& ps) const
+ {
+ if (ps.p_of_run() < nruns()
+ && ps.p_in_run() < con_[ps.p_of_run()].length())
+ return (ps == con_[ps.p_of_run()][ps.p_in_run()]);
+ else
+ return false;
+ }
+
+ template <typename P>
+ inline
+ const box_<P>&
+ p_runs_<P>::bbox() const
+ {
+ return fb_.to_result();
+ }
+
+ template <typename P>
+ inline
+ typename std::size_t
+ p_runs_<P>::npoints() const
+ {
+ return npoints_;
+ }
+
+ template <typename P>
+ inline
+ void
+ p_runs_<P>::insert(const p_run<P>& pr)
+ {
+ typename std::vector<p_run<P> >::const_iterator iter =
con_.vect().begin();
+ while (iter != con_.vect().end() && iter->first() < pr.first())
+ ++iter;
+
+ if (iter != con_.vect().begin())
+ {
+ typename std::vector<p_run<P> >::const_iterator prec = iter;
+ --prec;
+ bool equal = true;
+ for (int i = P::dim - 2; i >= 0; --i)
+ if (!(equal = equal && (prec->first()[i] == pr.first()[i])))
+ break;
+ if (equal)
+ mln_assertion(prec->first()[P::dim - 1] + (signed)prec->length()
+ <= pr.first()[P::dim - 1]);
+ }
+
+ if (iter != con_.vect().end())
+ {
+ bool equal = true;
+ for (int i = P::dim - 2; i >= 0; --i)
+ if (!(equal = equal && ((*iter).first()[i] == pr.first()[i])))
+ break;
+ if (equal)
+ mln_assertion(pr.first()[P::dim - 1] + (signed)pr.length()
+ <= iter->first()[P::dim - 1]);
+ }
+ con_.insert(pr);
+
+ // update box
+ fb_.take(pr.bbox().pmin());
+ fb_.take(pr.bbox().pmax());
+ // update size
+ npoints_ += pr.npoints();
+ }
+
+ template <typename P>
+ inline
+ unsigned
+ p_runs_<P>::nruns() const
+ {
+ return con_.nelements();
+ }
+
+ template <typename P>
+ inline
+ unsigned
+ p_runs_<P>::range_len_(const P& p) const
+ {
+ unsigned i;
+ for (i = 0; i < con_.size(); ++i)
+ {
+ if (con_[i].first == p)
+ return con_[i].second;
+ }
+ mln_assertion(i < con_.size());
+
+ //Hack
+ return (con_[i].second);
+ }
+
+ template <typename P>
+ inline
+ const p_run<P>&
+ p_runs_<P>::operator[](unsigned i) const
+ {
+ return con_[i];
+ }
+
+ template <typename P>
+ inline
+ unsigned
+ p_runs_<P>::size_mem() const
+ {
+ if (con_.get_mode())
+ return nruns() * (sizeof(P) + sizeof(unsigned));
+ else
+ return 2 * nruns() * (sizeof(P) + sizeof(unsigned));
+ }
+
+ template <typename P>
+ inline
+ void
+ p_runs_<P>::finalize()
+ {
+ con_.set_const_mode(true);
+ }
+
+
+// template <typename P>
+// const typename p_runs_<P>::container&
+// p_runs_<P>::con() const
+// {
+// return con_;
+// }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ /*! \brief Factorization class for p_runs_iterator_.
+ *
+ * Parameter \c P is the type of the point used in the point set.
+ * Parameter \c E is the exact type of the iterator
+ */
+ template <typename P, typename E>
+ class p_runs_piter_ : public internal::point_iterator_base_< runs_psite<P>, E
>
+ {
+ public:
+
+ /// Convertion into a point.
+ operator P () const;
+
+ /// Reference to the corresponding point.
+ const P& to_point() const;
+
+ /// Access to the current point coordinates.
+ mln_coord(P) operator[](unsigned i) const;
+
+ protected:
+
+ /// Current point.
+ P p_;
+
+ /// Point set container.
+ const p_runs_<P>& con_;
+
+ p_runs_piter_(const p_runs_<P>& pset);
+ };
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename P, typename E>
+ inline
+ p_runs_piter_<P, E>::p_runs_piter_(const p_runs_<P>& pset) :
+ con_(pset)
+ {
+ }
+
+ template <typename P, typename E>
+ inline
+ p_runs_piter_<P, E>::operator P () const
+ {
+ return this->to_point();
+ }
+
+ template <typename P, typename E>
+ inline
+ const P&
+ p_runs_piter_<P, E>::to_point() const
+ {
+ mln_precondition(exact(this)->is_valid());
+ return p_;
+ }
+
+ template <typename P, typename E>
+ inline
+ mln_coord(P)
+ p_runs_piter_<P, E>::operator[] (unsigned i) const
+ {
+ mln_precondition(exact(this)->is_valid());
+ return p_[i];
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+
+ /*! \brief Forward iterator on p_runs_ point set.
+ *
+ * Parameter \c P is the type of the point used in the point set.
+ */
+ template <typename P>
+ class p_runs_fwd_piter_ : public p_runs_piter_<P, p_runs_fwd_piter_<P> >
+ {
+ typedef p_runs_piter_<P, p_runs_fwd_piter_<P> > super;
+ public:
+
+ p_runs_fwd_piter_(const p_runs_<P>& pset);
+
+ /// Test the iterator validity.
+ bool is_valid() const;
+
+ /// Invalidate the iterator.
+ void invalidate();
+
+ /// Start an iteration.
+ void start();
+
+ /// Go to the next point.
+ void next_();
+
+ /// Convertion into a point-site.
+ operator runs_psite<P> () const;
+
+ protected:
+
+ unsigned i_;
+
+ p_run_fwd_piter_<P> it_;
+ };
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename P>
+ inline
+ p_runs_fwd_piter_<P>::p_runs_fwd_piter_(const p_runs_<P>& pset) :
+ super(pset)
+ {
+ invalidate();
+ }
+
+ template <typename P>
+ inline
+ bool
+ p_runs_fwd_piter_<P>::is_valid() const
+ {
+ return i_ < this->con_.nruns();
+ }
+
+ template <typename P>
+ inline
+ void
+ p_runs_fwd_piter_<P>::invalidate()
+ {
+ i_ = this->con_.nruns();
+ }
+
+ template <typename P>
+ inline
+ void
+ p_runs_fwd_piter_<P>::start()
+ {
+ i_ = 0;
+ it_.assign_run(this->con_[i_]);
+ it_.start();
+ this->p_ = it_;
+ }
+
+ template <typename P>
+ inline
+ void
+ p_runs_fwd_piter_<P>::next_()
+ {
+ mln_precondition(this->is_valid());
+ it_.next();
+ if (!it_.is_valid())
+ {
+ ++i_;
+ if (is_valid())
+ {
+ it_.assign_run(this->con_[i_]);
+ it_.start();
+ }
+ else
+ return;
+ }
+ this->p_ = it_;
+ }
+
+ template <typename P>
+ p_runs_fwd_piter_<P>::operator runs_psite<P> () const
+ {
+ return runs_psite<P>(this->con_, it_.ind(), i_);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+
+ /*! \brief Backward iterator on p_runs_ point set.
+ *
+ * Parameter \c P is the type of the point used in the point set.
+ */
+ template <typename P>
+ class p_runs_bkd_piter_ : public p_runs_piter_<P, p_runs_bkd_piter_<P> >
+ {
+ typedef p_runs_piter_<P, p_runs_bkd_piter_<P> > super;
+ public:
+
+ p_runs_bkd_piter_(const p_runs_<P>& pset);
+
+ /// Test the iterator validity.
+ bool is_valid() const;
+
+ /// Invalidate the iterator.
+ void invalidate();
+
+ /// Start an iteration.
+ void start();
+
+ /// Go to the next point.
+ void next_();
+
+ /// Convertion into a point-site.
+ operator runs_psite<P> () const;
+
+ protected:
+
+ unsigned i_;
+
+ p_run_bkd_piter_<P> it_;
+};
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename P>
+ inline
+ p_runs_bkd_piter_<P>::p_runs_bkd_piter_(const p_runs_<P>& pset) :
+ super(pset)
+ {
+ invalidate();
+ }
+
+ template <typename P>
+ inline
+ bool
+ p_runs_bkd_piter_<P>::is_valid() const
+ {
+ return i_ < this->con_.nruns();
+ }
+
+ template <typename P>
+ inline
+ void
+ p_runs_bkd_piter_<P>::invalidate()
+ {
+ i_ = this->con_.nruns();
+ }
+
+ template <typename P>
+ inline
+ void
+ p_runs_bkd_piter_<P>::start()
+ {
+ i_ = this->con_.nruns() - 1;
+ it_.assign_run(this->con_[i_]);
+ it_.start();
+ this->p_ = it_;
+ }
+
+ template <typename P>
+ inline
+ void
+ p_runs_bkd_piter_<P>::next_()
+ {
+ mln_precondition(this->is_valid());
+ it_.next();
+ if (!it_.is_valid())
+ {
+ --i_;
+ if (is_valid())
+ {
+ it_.assign_run(this->con_[i_]);
+ it_.start();
+ }
+ else
+ return;
+ }
+ this->p_ = it_;
+ }
+
+ template <typename P>
+ p_runs_bkd_piter_<P>::operator runs_psite<P> () const
+ {
+ return runs_psite<P>(this->con_, it_.ind(), i_);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_P_RUNS_HH
Index: trunk/milena/sandbox/pellegrin/set/core/p_set.hh
===================================================================
--- trunk/milena/sandbox/pellegrin/set/core/p_set.hh (revision 1789)
+++ trunk/milena/sandbox/pellegrin/set/core/p_set.hh (revision 1790)
@@ -37,16 +37,20 @@
# include <mln/core/internal/set_of.hh>
# include <mln/accu/bbox.hh>
# include <mln/core/p_array.hh>
+# include <mln/trait/point_set.hh>
namespace mln
{
+ // Fwd decls.
+ template <typename P> struct p_set;
+
namespace trait
{
template <typename P>
- struct point_set_<line2d> : public default_point_set_<P>
+ struct point_set_< p_set<P> > : public default_point_set_<
p_set<P> >
{
typedef trait::point_set::arity::unique arity;
typedef trait::point_set::has_speed::fast has_speed;
Index: trunk/milena/sandbox/pellegrin/set/core/p_priority_queue_fast_with_array.hh
===================================================================
--- trunk/milena/sandbox/pellegrin/set/core/p_priority_queue_fast_with_array.hh (revision
1789)
+++ trunk/milena/sandbox/pellegrin/set/core/p_priority_queue_fast_with_array.hh (revision
1790)
@@ -44,21 +44,25 @@
# include <mln/core/p_array_piter.hh>
# include <mln/accu/bbox.hh>
# include <mln/core/p_queue_fast.hh>
+# include <mln/trait/point_set.hh>
+
namespace mln
{
// Fwd decls.
+ template <typename P, typename T, typename S> struct
p_priority_queue_fast_with_array;
template <typename P> struct p_array_fwd_piter_;
template <typename P> struct p_array_bkd_piter_;
namespace trait
{
- template <typename P>
- struct point_set_<line2d> : public default_point_set_<P>
+ template <typename P, typename T, typename S>
+ struct point_set_< p_priority_queue_fast_with_array<P, T, S> >
+ : public default_point_set_< p_priority_queue_fast_with_array<P, T, S> >
{
- typedef trait::point_set::arity::unique arity;
+ typedef trait::point_set::arity::multiple arity;
typedef trait::point_set::has_speed::fast has_speed;
}
Index: trunk/milena/sandbox/pellegrin/set/core/line2d.hh
===================================================================
--- trunk/milena/sandbox/pellegrin/set/core/line2d.hh (revision 1789)
+++ trunk/milena/sandbox/pellegrin/set/core/line2d.hh (revision 1790)
@@ -39,16 +39,20 @@
# include <mln/core/p_array_piter.hh>
# include <mln/core/box2d.hh>
# include <mln/math/all.hh>
+# include <mln/trait/point_set.hh>
namespace mln
{
+ // Fwd decl.
+ template <typename P> struct line2d;
+
namespace trait
{
- template <typename P>
- struct point_set_<line2d> : public default_point_set_<P>
+ template <>
+ struct point_set_<line2d> : public default_point_set_<line2d>
{
typedef trait::point_set::arity::unique arity;
typedef trait::point_set::has_speed::fast has_speed;
Index: trunk/milena/sandbox/pellegrin/set/core/p_graph.hh
===================================================================
--- trunk/milena/sandbox/pellegrin/set/core/p_graph.hh (revision 1789)
+++ trunk/milena/sandbox/pellegrin/set/core/p_graph.hh (revision 1790)
@@ -34,6 +34,8 @@
# include <mln/util/graph.hh>
# include <mln/core/graph_psite.hh>
# include <mln/core/p_graph_piter.hh>
+# include <mln/trait/point_set.hh>
+
/// \file mln/core/p_graph.hh
/// \brief Definition of a point set based on graph.
@@ -41,13 +43,15 @@
namespace mln
{
+ // Fwd decls.
+ template <typename P> struct p_graph;
template<typename P> class p_graph_piter_;
namespace trait
{
template <typename P>
- struct point_set_<line2d> : public default_point_set_<P>
+ struct point_set_< p_graph<P> > : public default_point_set_<
p_graph<P> >
{
typedef trait::point_set::arity::unique arity;
typedef trait::point_set::has_speed::fast has_speed;
Index: trunk/milena/sandbox/pellegrin/set/core/p_queue_fast.hh
===================================================================
--- trunk/milena/sandbox/pellegrin/set/core/p_queue_fast.hh (revision 1789)
+++ trunk/milena/sandbox/pellegrin/set/core/p_queue_fast.hh (revision 1790)
@@ -42,12 +42,14 @@
# include <mln/core/internal/point_set_base.hh>
# include <mln/core/p_array_piter.hh>
# include <mln/accu/bbox.hh>
+# include <mln/trait/point_set.hh>
namespace mln
{
// Fwd decls.
+ template <typename P> struct p_queue_fast;
template <typename P> struct p_array_fwd_piter_;
template <typename P> struct p_array_bkd_piter_;
@@ -55,9 +57,9 @@
{
template <typename P>
- struct point_set_<line2d> : public default_point_set_<P>
+ struct point_set_< p_queue_fast<P> > : public default_point_set_<
p_queue_fast<P> >
{
- typedef trait::point_set::arity::unique arity;
+ typedef trait::point_set::arity::multiple arity;
typedef trait::point_set::has_speed::fast has_speed;
}
--
Michel PELLEGRIN
ÉPITA - CSI 2010