URL:
https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-11-29 Simon Nivault <simon.nivault(a)lrde.epita.fr>
Iteration on runs_psite works.
* mln/core/internal/run_psite.hh: Rename as...
* mln/core/runs_psite.hh: ...this.
* mln/core/macros.hh: Add macros without typename.
* mln/core/p_run_piter.hh,
* mln/core/p_runs.hh,
* mln/util/lazy_set.hh: Fix.
* tests/p_runs.cc: Add test for iterations.
---
mln/core/macros.hh | 29 +++++-
mln/core/p_run_piter.hh | 64 ++++++++++++--
mln/core/p_runs.hh | 179 +++++++++++++++++++++++++---------------
mln/core/runs_psite.hh | 214 ++++++++++++++++++++++++++++++++++++++++++++++++
mln/util/lazy_set.hh | 4
tests/p_runs.cc | 21 +++-
6 files changed, 424 insertions(+), 87 deletions(-)
Index: trunk/milena/tests/p_runs.cc
===================================================================
--- trunk/milena/tests/p_runs.cc (revision 1572)
+++ trunk/milena/tests/p_runs.cc (revision 1573)
@@ -57,8 +57,8 @@
r = make::point2d(50, 76);
// Psite declaration
- internal::run_psite<point2d> site(p, 5, 0);
- internal::run_psite<point2d> site2(r, 40, 0);
+ runs_psite<point2d> site(p, 5, 0);
+ runs_psite<point2d> site2(r, 40, 0);
// Pset test
p_runs_<point2d> ps;
@@ -66,15 +66,26 @@
ps.insert(p_run<point2d>(p, 7));
mln_assertion(ps.npoints() == 7);
- ps.insert(p_run<point2d>(q, 42));
- mln_assertion(ps.npoints() == 49);
+ ps.insert(p_run<point2d>(q, 5));
+ mln_assertion(ps.npoints() == 12);
mln_assertion(ps.has(site));
mln_assertion(!ps.has(site2));
- ps.insert(p_run<point2d>(r, 14));
+ ps.insert(p_run<point2d>(r, 2));
mln_assertion(!ps.has(site2));
ps.insert(p_run<point2d>(make::point2d(17,40), 6));
+ mln_fwd_piter_(p_runs_<point2d>) ppf(ps);
+ for_all(ppf)
+ {
+ std::cout << ppf << std::endl;
+ }
+ std::cout << std::endl;
+ mln_bkd_piter_(p_runs_<point2d>) ppb(ps);
+ for_all(ppb)
+ {
+ std::cout << ppb << std::endl;
+ }
// parc(ps);
}
Index: trunk/milena/mln/core/macros.hh
===================================================================
--- trunk/milena/mln/core/macros.hh (revision 1572)
+++ trunk/milena/mln/core/macros.hh (revision 1573)
@@ -45,36 +45,44 @@
/// Shortcut to access the bkd_niter type associated to T.
# define mln_bkd_niter(T) typename T::bkd_niter
+# define mln_bkd_niter_(T) T::bkd_niter
/// Shortcut to access the bkd_piter type associated to T.
# define mln_bkd_piter(T) typename T::bkd_piter
+# define mln_bkd_piter_(T) T::bkd_piter
/// Shortcut to access the bkd_qiter type associated to T.
# define mln_bkd_qiter(T) typename T::bkd_qiter
+# define mln_bkd_qiter_(T) T::bkd_qiter
/// Shortcut to access the bkd_viter type associated to T.
# define mln_bkd_viter(T) typename T::bkd_viter
+# define mln_bkd_viter_(T) T::bkd_viter
/// Shortcut to access the box type associated to T.
# define mln_box(T) typename T::box
+# define mln_box_(T) T::box
// c
/// Shortcut to access the coord type associated to T.
# define mln_coord(T) typename T::coord
+# define mln_coord_(T) T::coord
// d
/// Shortcut to access the dpoint type associated to T.
# define mln_dpoint(T) typename T::dpoint
+# define mln_dpoint_(T) T::dpoint
// e
/// Shortcut to access the encoding type associated to T.
# define mln_enc(T) typename T::enc
+# define mln_enc_(T) T::enc
/// Shortcut to access the equivalent type associated to T.
# define mln_equiv(T) typename T::equiv
@@ -85,18 +93,19 @@
/// Shortcut to access the fwd_niter type associated to T.
# define mln_fwd_niter(T) typename T::fwd_niter
+# define mln_fwd_niter_(T) T::fwd_niter
/// Shortcut to access the fwd_piter type associated to T.
# define mln_fwd_piter(T) typename T::fwd_piter
-
-/// Shortcut to access the bkd_piter type associated to T.
-# define mln_bkd_piter(T) typename T::bkd_piter
+# define mln_fwd_piter_(T) T::fwd_piter
/// Shortcut to access the fwd_qiter type associated to T.
# define mln_fwd_qiter(T) typename T::fwd_qiter
+# define mln_fwd_qiter_(T) T::fwd_qiter
/// Shortcut to access the fwd_viter type associated to T.
# define mln_fwd_viter(T) typename T::fwd_viter
+# define mln_fwd_viter_(T) T::fwd_viter
// i
@@ -114,6 +123,7 @@
/// Shortcut to access the lvalue type associated to T.
# define mln_lvalue(T) typename T::lvalue
+# define mln_lvalue_(T) T::lvalue
// m
@@ -121,6 +131,7 @@
/// Shortcut to access the mesh type associated to T.
# define mln_mesh(T) typename T::mesh
+# define mln_mesh_(T) T::mesh
// p
@@ -131,30 +142,37 @@
/// Shortcut to access the type of point by line iterator (line_piter) associated to T.
# define mln_line_piter(T) typename T::line_piter
+# define mln_line_piter_(T) T::line_piter
/// Shortcut to access the type of point set (pset) associated to T.
# define mln_pset(T) typename T::pset
+# define mln_pset_(T) T::pset
/// Shortcut to access the type of point site (psite) associated to T.
# define mln_psite(T) typename T::psite
+# define mln_psite_(T) T::psite
/// Shortcut to access the point type associated to T.
# define mln_point(T) typename T::point
+# define mln_point_(T) T::point
// q
/// Shortcut to access the qualified (const or mutable) value type associated to T.
# define mln_qlf_value(T) typename mln::trait::qlf_value< T >::ret
+# define mln_qlf_value_(T) mln::trait::qlf_value< T >::ret
/// Shortcut to access the qiter type associated to T.
# define mln_qiter(T) typename T::fwd_qiter
+# define mln_qiter_(T) T::fwd_qiter
// n
/// Shortcut to access the niter type associated to T.
# define mln_niter(T) typename T::fwd_niter
+# define mln_niter_(T) T::fwd_niter
// r
@@ -165,6 +183,7 @@
/// Shortcut to access the rvalue type associated to T.
# define mln_rvalue(T) typename T::rvalue
+# define mln_rvalue_(T) T::rvalue
// v
@@ -175,18 +194,22 @@
/// Shortcut to access the type of value set (vset) associated to T.
# define mln_vset(T) typename T::vset
+# define mln_vset_(T) T::vset
/// Shortcut to access the viter type associated to T.
# define mln_viter(T) typename T::fwd_viter
+# define mln_viter_(T) T::fwd_viter
// w
/// Shortcut to access the weight type associated to T.
# define mln_weight(T) typename T::weight
+# define mln_weight_(T) T::weight
/// Shortcut to access the window type associated to T.
# define mln_window(T) typename T::window
+# define mln_window_(T) T::window
Index: trunk/milena/mln/core/internal/run_psite.hh (deleted)
===================================================================
Index: trunk/milena/mln/core/runs_psite.hh
===================================================================
--- trunk/milena/mln/core/runs_psite.hh (revision 0)
+++ trunk/milena/mln/core/runs_psite.hh (revision 1573)
@@ -0,0 +1,214 @@
+// 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_RUNS_PSITE_HH
+# define MLN_CORE_RUNS_PSITE_HH
+
+/*! \file mln/core/runs_psite.hh
+ *
+ * \brief Definition of class mln::runs_psite_ for internal use only
+ */
+
+# include <mln/core/concept/point_site.hh>
+
+
+namespace mln
+{
+ // Fwd decl.
+ template <typename P> class p_runs_;
+
+ /*! \brief Psite class used in run_image_.
+ *
+ * Parameter \c P is the type of the image point.
+ */
+ template <typename P>
+ class runs_psite : public Point_Site< runs_psite<P> >
+ {
+ public:
+
+ typedef mln_mesh(P) mesh;
+ enum { dim = P::dim };
+ typedef P point;
+ typedef mln_dpoint(P) dpoint;
+ typedef mln_coord(P) coord;
+
+ runs_psite();
+ runs_psite(const p_runs_<P>& pr, const P& p);
+ runs_psite(P point, unsigned index, unsigned pset_pos);
+
+ operator P () const;
+
+ /// Return the point at the start of the current run.
+ P& range_start_();
+
+ /// Return the point at the start of the current run.
+ const P& range_start_() const;
+
+ /// Return the position of this psite in the point set.
+ unsigned pset_pos_() const;
+
+ /// Return the position of this psite in the point set.
+ unsigned& pset_pos_();
+
+ /// Return the position of this psite in the current range.
+ unsigned index_() const;
+
+ /// Return the position of this psite in the current range.
+ unsigned& index_();
+
+ /// Reference to the corresponding point.
+ const P& to_point() const;
+
+ /// Give the i-th coordinate of the corresponding point.
+ mln_coord(P) operator[](unsigned i) const;
+
+ protected:
+
+ /// Start of the psite range.
+ P p_; // FIXME: Rename as p_ (like everywhere else!)
+
+ /// Position in the psite range.
+ unsigned range_index_;
+
+ /// Position of the psite in the point set.
+ unsigned pset_position_;
+ };
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename P>
+ inline
+ runs_psite<P>::runs_psite(const p_runs_<P>& pr, const P& p)
+ {
+ unsigned i = 0;
+ while (i < pr.nruns() && p < pr[i].first())
+ ++i;
+ mln_assertion(i != 0);
+
+ range_index_ = p[P::dim - 1] - pr[i].first()[P::dim - 1];
+
+ mln_assertion(pr[i - 1].npoints() > range_index_);
+
+ pset_position_ = i - 1;
+ p_ = pr[pset_position_].first();
+ }
+
+ template <typename P>
+ inline
+ runs_psite<P>::runs_psite(P point, unsigned index, unsigned pset_pos) :
+ p_(point),
+ range_index_(index),
+ pset_position_(pset_pos)
+ {
+ }
+
+ template <typename P>
+ inline
+ runs_psite<P>::operator P() const
+ {
+ P p = p_;
+ p[dim - 1] += range_index_;
+ return p;
+ }
+
+ template <typename P>
+ inline
+ const P&
+ runs_psite<P>::range_start_() const
+ {
+ return p_;
+ }
+
+ template <typename P>
+ inline
+ P&
+ runs_psite<P>::range_start_()
+ {
+ return p_;
+ }
+
+ template <typename P>
+ inline
+ unsigned
+ runs_psite<P>::pset_pos_() const
+ {
+ return pset_position_;
+ }
+
+ template <typename P>
+ inline
+ unsigned&
+ runs_psite<P>::pset_pos_()
+ {
+ return pset_position_;
+ }
+
+ template <typename P>
+ inline
+ unsigned
+ runs_psite<P>::index_() const
+ {
+ return range_index_;
+ }
+
+ template <typename P>
+ inline
+ unsigned&
+ runs_psite<P>::index_()
+ {
+ return range_index_;
+ }
+
+ template <typename P>
+ inline
+ const P&
+ runs_psite<P>::to_point() const
+ {
+ static P p = p_;
+ p[dim - 1] += range_index_;
+ return p;
+ }
+
+ template <typename P>
+ inline
+ mln_coord(P)
+ runs_psite<P>::operator[](unsigned i) const
+ {
+ mln_precondition(i < dim);
+ if (i == dim - 1)
+ return p_[i] + range_index_;
+ else
+ return p_[i];
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_INTERNAL_RUNS_PSITE_HH
Index: trunk/milena/mln/core/p_run_piter.hh
===================================================================
--- trunk/milena/mln/core/p_run_piter.hh (revision 1572)
+++ trunk/milena/mln/core/p_run_piter.hh (revision 1573)
@@ -52,9 +52,15 @@
// Make definitions from super class available.
enum { dim = super_::dim };
+ /// Constructor without arguments.
+ p_run_fwd_piter_();
+
/// Coordinate associated type.
p_run_fwd_piter_(const p_run<P>& pr);
+ /// Assign a new run to iterate.
+ void assign_run(const p_run<P>& pr);
+
/// Reference of the corresponding point.
const P& to_point() const;
@@ -77,7 +83,7 @@
operator P() const;
protected:
- const p_run<P>& run_;
+ const p_run<P>* run_;
bool is_valid_;
P p_;
};
@@ -97,9 +103,15 @@
// Make definitions from super class available.
enum { dim = super_::dim };
+ /// Constructor without arguments.
+ p_run_bkd_piter_();
+
/// Coordinate associated type.
p_run_bkd_piter_(const p_run<P>& pr);
+ /// Assign a new run to iterate.
+ void assign_run(const p_run<P>& pr);
+
/// Reference of the corresponding point.
const P& to_point() const;
@@ -122,7 +134,7 @@
operator P() const;
protected:
- const p_run<P>& run_;
+ const p_run<P>* run_;
bool is_valid_;
P p_;
};
@@ -135,9 +147,25 @@
template <typename P>
inline
+ p_run_fwd_piter_<P>::p_run_fwd_piter_()
+ : run_ (0)
+ {
+ }
+
+ template <typename P>
+ inline
p_run_fwd_piter_<P>::p_run_fwd_piter_(const p_run<P>& pr)
- : run_(pr)
+ : run_(&pr)
+ {
+ invalidate();
+ }
+
+ template <typename P>
+ inline
+ void
+ p_run_fwd_piter_<P>::assign_run(const p_run<P>& pr)
{
+ run_ = ≺
invalidate();
}
@@ -181,7 +209,7 @@
void
p_run_fwd_piter_<P>::start()
{
- p_ = run_.first();
+ p_ = run_->first();
is_valid_ = true;
}
@@ -191,7 +219,7 @@
p_run_fwd_piter_<P>::next_()
{
p_[dim - 1]++;
- is_valid_ = p_[dim - 1] - run_.first()[dim - 1] < (signed)run_.length();
+ is_valid_ = p_[dim - 1] - run_->first()[dim - 1] < (signed)run_->length();
}
template <typename P>
@@ -207,14 +235,30 @@
template <typename P>
inline
+ p_run_bkd_piter_<P>::p_run_bkd_piter_()
+ : run_ (0)
+ {
+ }
+
+ template <typename P>
+ inline
p_run_bkd_piter_<P>::p_run_bkd_piter_(const p_run<P>& pr)
- : run_(pr)
+ : run_(&pr)
{
invalidate();
}
template <typename P>
inline
+ void
+ p_run_bkd_piter_<P>::assign_run(const p_run<P>& pr)
+ {
+ run_ = ≺
+ invalidate();
+ }
+
+ template <typename P>
+ inline
const P&
p_run_bkd_piter_<P>::to_point() const
{
@@ -237,7 +281,7 @@
bool
p_run_bkd_piter_<P>::is_valid() const
{
- return is_valid;
+ return is_valid_;
}
template <typename P>
@@ -253,7 +297,7 @@
void
p_run_bkd_piter_<P>::start()
{
- p_ = run_[run_.length() - 1];
+ p_ = (*run_)[run_->length() - 1];
is_valid_ = true;
}
@@ -262,8 +306,8 @@
void
p_run_bkd_piter_<P>::next_()
{
- p_[dim - 1]++;
- is_valid_ = p_[dim - 1] - run_.first()[dim - 1] >= 0;
+ p_[dim - 1]--;
+ is_valid_ = p_[dim - 1] - run_->first()[dim - 1] >= 0;
}
template <typename P>
Index: trunk/milena/mln/core/p_runs.hh
===================================================================
--- trunk/milena/mln/core/p_runs.hh (revision 1572)
+++ trunk/milena/mln/core/p_runs.hh (revision 1573)
@@ -36,7 +36,7 @@
# include <mln/core/internal/point_set_base.hh>
# include <mln/core/internal/point_iterator_base.hh>
-# include <mln/core/internal/run_psite.hh>
+# include <mln/core/runs_psite.hh>
# include <mln/core/p_run.hh>
# include <mln/accu/bbox.hh>
# include <mln/util/lazy_set.hh>
@@ -58,19 +58,19 @@
* Parameter \c P is the type of the image point.
*/
template <typename P>
- class p_runs_ : public internal::point_set_base_< internal::run_psite<P>,
p_runs_<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 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 internal::run_psite<P>& p) const;
+ bool has(const runs_psite<P>& p) const;
/// Give the exact bounding box.
const box_<P>& bbox() const;
@@ -81,11 +81,17 @@
/// 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 container of the pset (internal use only).
- const container& con() const;
+ /// Return the i-th run of the list of runs
+ const p_run<P>& operator[](unsigned i) const;
+
+// /// Return the container of the pset (internal use only).
+// const container& con() const;
protected:
@@ -93,7 +99,7 @@
typename std::size_t npoints_;
/// Points container
- container con_;
+ util::lazy_set_<p_run<P> > con_;
/// Exact bounding box.
accu::bbox<P> fb_;
@@ -111,7 +117,7 @@
template <typename P>
inline
bool
- p_runs_<P>::has(const internal::run_psite<P>& p) const
+ p_runs_<P>::has(const runs_psite<P>& p) const
{
for (unsigned i = 0; i < con_.nelements(); ++i)
{
@@ -181,6 +187,14 @@
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;
@@ -189,7 +203,7 @@
if (con_[i].first == p)
return con_[i].second;
}
- mln_assertion(i < con.size());
+ mln_assertion(i < con_.size());
//Hack
return (con_[i].second);
@@ -197,12 +211,19 @@
template <typename P>
inline
- const typename p_runs_<P>::container&
- p_runs_<P>::con() const
+ const p_run<P>&
+ p_runs_<P>::operator[](unsigned i) const
{
- return con_;
+ return con_[i];
}
+// 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_.
@@ -211,13 +232,12 @@
* Parameter \c E is the exact type of the iterator
*/
template <typename P, typename E>
- class p_runs_piter_ : public internal::point_iterator_base_<
internal::run_psite<P>, E >
+ class p_runs_piter_ : public internal::point_iterator_base_< runs_psite<P>, E
>
{
public:
- typedef typename p_runs_<P>::std_container std_container;
/// Convertion into a point-site.
- operator internal::run_psite<P> () const;
+ operator runs_psite<P> () const;
/// Convertion into a point.
operator P () const;
@@ -233,11 +253,8 @@
/// Current point.
P p_;
- /// Current site.
- internal::run_psite<P> site_;
-
/// Point set container.
- const std_container& con_;
+ const p_runs_<P>& con_;
p_runs_piter_(const p_runs_<P>& pset);
};
@@ -246,24 +263,27 @@
# 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.con())
+ con_(pset)
{
}
template <typename P, typename E>
- p_runs_piter_<P, E>::operator internal::run_psite<P> () const
+ p_runs_piter_<P, E>::operator runs_psite<P> () const
{
- return site_;
+ return runs_psite<P>(con_, p_);
}
template <typename P, typename E>
+ inline
p_runs_piter_<P, E>::operator P () const
{
- return p_;
+ return this->to_point();
}
template <typename P, typename E>
+ inline
const P&
p_runs_piter_<P, E>::to_point() const
{
@@ -272,6 +292,7 @@
}
template <typename P, typename E>
+ inline
mln_coord(P)
p_runs_piter_<P, E>::operator[] (unsigned i) const
{
@@ -307,63 +328,83 @@
void next_();
protected:
- typename super::std_container::const_iterator it_;
- };
+ 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)
{
- it_ = this->con_.end();
- this->site_.pset_pos_() = this->con_.size();
+ invalidate();
}
template <typename P>
+ inline
bool
p_runs_fwd_piter_<P>::is_valid() const
{
- return it_ != this->con_.end();
+ return i_ < this->con_.nruns();
}
template <typename P>
+ inline
void
p_runs_fwd_piter_<P>::invalidate()
{
- it_ = this->con_.end();
- this->site_.pset_pos_() = this->con_.size();
+ i_ = this->con_.nruns();
}
template <typename P>
+ inline
void
p_runs_fwd_piter_<P>::start()
{
- it_ = this->con_.begin();
- this->site_.range_start_() = it_->first;
- this->site_.index_() = 0;
- this->site_.pset_pos_() = 0;
- this->p_ = it_->first;
+ 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());
- ++(this->site_.index_());
-
- if (this->site_.index_() >= it_->second)
+ it_.next();
+ if (!it_.is_valid())
{
- ++it_;
- ++this->site_.pset_pos_();
- this->site_.range_start_() = it_->first;
- this->site_.index_() = 0;
+ ++i_;
+ if (is_valid())
+ {
+ it_.assign_run(this->con_[i_]);
+ it_.start();
+ }
+ else
+ return;
}
- this->p_ = this->site_.range_start_();
- this->p_[0] += this->site_.index_();
+ this->p_ = it_;
+
+
+// mln_precondition(this->is_valid());
+// ++(this->site_.index_());
+
+// if (this->site_.index_() >= it_->second)
+// {
+// ++it_;
+// ++this->site_.pset_pos_();
+// this->site_.range_start_() = it_->first;
+// this->site_.index_() = 0;
+// }
+// this->p_ = this->site_.range_start_();
+// this->p_[0] += this->site_.index_();
}
# endif // ! MLN_INCLUDE_ONLY
@@ -394,7 +435,10 @@
void next_();
protected:
- typename super::std_container::const_reverse_iterator it_;
+
+ unsigned i_;
+
+ p_run_bkd_piter_<P> it_;
};
@@ -402,56 +446,59 @@
# ifndef MLN_INCLUDE_ONLY
template <typename P>
+ inline
p_runs_bkd_piter_<P>::p_runs_bkd_piter_(const p_runs_<P>& pset) :
super(pset)
{
- it_ = this->con_.rend();
- this->site_.pset_pos_() = this->con_.size();
+ invalidate();
}
template <typename P>
+ inline
bool
p_runs_bkd_piter_<P>::is_valid() const
{
- return it_ != this->con_.rend();
+ return i_ < this->con_.nruns();
}
template <typename P>
+ inline
void
p_runs_bkd_piter_<P>::invalidate()
{
- it_ = this->con_.rend();
- this->site_.pset_pos_() = this->con_.size();
+ i_ = this->con_.nruns();
}
template <typename P>
+ inline
void
p_runs_bkd_piter_<P>::start()
{
- it_ = this->con_.rbegin();
- this->site_.range_start_() = it_->first;
- this->site_.index_() = it_->second - 1;
- this->site_.pset_pos_() = this->con_.size() - 1;
- this->p_ = this->site_.range_start_();
- this->p_[0] += this->site_.index_();
+ 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());
- --(this->site_.index_());
-
- if (this->site_.index_() + 1 == 0)
+ it_.next();
+ if (!it_.is_valid())
{
- ++it_;
- --this->site_.pset_pos_();
- this->site_.range_start_() = it_->first;
- this->site_.index_() = this->it_->second - 1;
+ --i_;
+ if (is_valid())
+ {
+ it_.assign_run(this->con_[i_]);
+ it_.start();
+ }
+ else
+ return;
}
- this->p_ = this->site_.range_start_();
- this->p_[0] += this->site_.index_();
+ this->p_ = it_;
}
# endif // ! MLN_INCLUDE_ONLY
Index: trunk/milena/mln/util/lazy_set.hh
===================================================================
--- trunk/milena/mln/util/lazy_set.hh (revision 1572)
+++ trunk/milena/mln/util/lazy_set.hh (revision 1573)
@@ -252,9 +252,7 @@
unsigned
lazy_set_<E>::nelements() const
{
- if (needs_update_)
- update_();
- return v_.size();
+ return s_.size();
}
template <typename E>