https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Prefer p() than p_ in site iterators.
For optimization purpose, we can have in site iterators a couple
of current location (see, e.g., in pset_if_piter.hh we have
this->p_ inherited plus the local pi_ attribute).
* mln/core/internal/site_iterator_base.hh (p): New.
(current_p_): New; can be overridden.
* mln/core/box_piter.hh: Update.
* mln/core/pset_if_piter.hh: Update.
* mln/core/box.hh: Update.
box.hh | 3 +++
box_piter.hh | 36 ++++++++++++++++++------------------
internal/site_iterator_base.hh | 23 +++++++++++++++++++----
pset_if_piter.hh | 11 +++++++----
4 files changed, 47 insertions(+), 26 deletions(-)
Index: mln/core/internal/site_iterator_base.hh
--- mln/core/internal/site_iterator_base.hh (revision 2051)
+++ mln/core/internal/site_iterator_base.hh (working copy)
@@ -41,6 +41,13 @@
# include <mln/core/concept/site_iterator.hh>
# include <mln/core/concept/pseudo_site.hh> // Use of if_possible::change_target.
+// site_iterator_base<S> where S is a Site_Set
+// {
+// s_ : const S*
+// }
+
+
+
namespace mln
{
@@ -96,6 +103,12 @@
/// Change the iterator target.
void change_target(const S& s);
+ mln_psite(S)& p() { return exact(this)->current_p_(); }
+ const mln_psite(S)& p() const { return exact(this)->current_p_(); }
+
+ mln_psite(S)& current_p_() { return p_; }
+ const mln_psite(S)& current_p_() const { return p_; }
+
protected:
site_iterator_base();
@@ -103,6 +116,8 @@
/// The target.
const S* s_;
+ private:
+
/// The psite designated by this iterator.
mln_psite(S) p_;
};
@@ -131,7 +146,7 @@
site_iterator_base<S, E>::to_site() const
{
mln_precondition(exact(*this).is_valid()); // FIXME: OK?
- return internal::to_site( exact(this)->unproxy() );
+ return internal::to_site( p() );
}
template <typename S, typename E>
@@ -139,7 +154,7 @@
const mln_psite(S)&
site_iterator_base<S, E>::unproxy() const
{
- return p_;
+ return p();
}
template <typename S, typename E>
@@ -156,9 +171,9 @@
site_iterator_base<S, E>::change_target(const S& s)
{
s_ = & s;
- // p_ might be also updated since it can hold a pointer towards
+ // p might be also updated since it can hold a pointer towards
// the set it designates, so:
- if_possible::change_target(p_, s);
+ if_possible::change_target(p(), s);
// Last:
this->invalidate();
}
Index: mln/core/box_piter.hh
--- mln/core/box_piter.hh (revision 2051)
+++ mln/core/box_piter.hh (working copy)
@@ -79,9 +79,9 @@
/// Go to the next point.
void next_();
- protected:
+ using super_::p;
- using super_::p_;
+ protected:
using super_::s_;
};
@@ -126,9 +126,9 @@
/// Go to the next point.
void next_();
- protected:
+ using super_::p;
- using super_::p_;
+ protected:
using super_::s_;
};
@@ -158,7 +158,7 @@
bool
box_fwd_piter_<P>::is_valid_() const
{
- return p_[0] != s_->pmax()[0] + 1;
+ return p()[0] != s_->pmax()[0] + 1;
}
template <typename P>
@@ -166,7 +166,7 @@
void
box_fwd_piter_<P>::invalidate_()
{
- p_[0] = s_->pmax()[0] + 1;
+ p()[0] = s_->pmax()[0] + 1;
}
template <typename P>
@@ -174,7 +174,7 @@
void
box_fwd_piter_<P>::start_()
{
- p_ = s_->pmin();
+ p() = s_->pmin();
}
template <typename P>
@@ -183,14 +183,14 @@
box_fwd_piter_<P>::next_()
{
for (int i = dim - 1; i >= 0; --i)
- if (p_[i] == s_->pmax()[i])
- p_[i] = s_->pmin()[i];
+ if (p()[i] == s_->pmax()[i])
+ p()[i] = s_->pmin()[i];
else
{
- ++p_[i];
+ ++p()[i];
break;
}
- if (p_ == s_->pmin())
+ if (p() == s_->pmin())
invalidate_();
}
@@ -215,7 +215,7 @@
bool
box_bkd_piter_<P>::is_valid_() const
{
- return p_[0] != s_->pmin()[0] - 1;
+ return p()[0] != s_->pmin()[0] - 1;
}
template <typename P>
@@ -223,7 +223,7 @@
void
box_bkd_piter_<P>::invalidate_()
{
- p_[0] = s_->pmin()[0] - 1;
+ p()[0] = s_->pmin()[0] - 1;
}
template <typename P>
@@ -231,7 +231,7 @@
void
box_bkd_piter_<P>::start_()
{
- p_ = s_->pmax();
+ p() = s_->pmax();
}
template <typename P>
@@ -240,14 +240,14 @@
box_bkd_piter_<P>::next_()
{
for (int i = dim - 1; i >= 0; --i)
- if (p_[i] == s_->pmin()[i])
- p_[i] = s_->pmax()[i];
+ if (p()[i] == s_->pmin()[i])
+ p()[i] = s_->pmax()[i];
else
{
- --p_[i];
+ --p()[i];
break;
}
- if (p_ == s_->pmax())
+ if (p() == s_->pmax())
invalidate_();
}
Index: mln/core/pset_if_piter.hh
--- mln/core/pset_if_piter.hh (revision 2051)
+++ mln/core/pset_if_piter.hh (working copy)
@@ -76,6 +76,9 @@
mln_fwd_piter(S)& hook_pi_() { return pi_; }
+ mln_psite(S)& current_p_() { return pi_.p(); }
+ const mln_psite(S)& current_p_() const { return pi_.p(); }
+
private:
mln_fwd_piter(S) pi_;
@@ -134,8 +137,8 @@
pi_.start();
while (pi_.is_valid() && ! this->s_->pred(pi_))
pi_.next();
- if (is_valid_())
- this->p_ = pi_;
+// if (is_valid_())
+// this->p_ = pi_;
}
template <typename S, typename F>
@@ -146,8 +149,8 @@
do
pi_.next();
while (pi_.is_valid() && ! this->s_->pred(pi_));
- if (is_valid_())
- this->p_ = pi_;
+// if (is_valid_())
+// this->p_ = pi_;
}
Index: mln/core/box.hh
--- mln/core/box.hh (revision 2051)
+++ mln/core/box.hh (working copy)
@@ -85,6 +85,9 @@
/// Forward Site_Iterator associated type.
typedef box_fwd_piter_<P> fwd_piter;
+ /// Site_Iterator associated type.
+ typedef fwd_piter piter;
+
/// Backward Site_Iterator associated type.
typedef box_bkd_piter_<P> bkd_piter;