cleanup-2008 2536: Fix accu::min_h and max_h.

https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena Index: ChangeLog from Thierry Geraud <thierry.geraud@lrde.epita.fr> Fix accu::min_h and max_h. * mln/accu/min_h.hh, * mln/accu/max_h.hh (debug_print_): New. (take): Fix. max_h.hh | 37 ++++++++++++++++++++++++++----------- min_h.hh | 18 ++++++++++++++++-- 2 files changed, 42 insertions(+), 13 deletions(-) Index: mln/accu/min_h.hh --- mln/accu/min_h.hh (revision 2535) +++ mln/accu/min_h.hh (working copy) @@ -68,6 +68,8 @@ const accu::histo<V>& histo() const; + void debug_print_() const; + protected: mutable accu::histo<V> h_; @@ -101,12 +103,12 @@ void min_h<V>::take(const argument& t) { - h_.take(t); - if (h_.sum() == 1) + if (h_.sum() == 0) { this->take_as_init(t); return; } + h_.take(t); if (t < t_) { ++sum_; @@ -233,6 +235,18 @@ template <typename V> inline + void + min_h<V>::debug_print_() const + { + std::cout << "h={" << h_ << "} "; + std::cout << "sum=" << sum_ << ' ' + << "valid=" << valid_ << ' ' + << "i=" << i_ << ' ' + << "t=" << t_ << std::endl; + } + + template <typename V> + inline std::ostream& operator<<(std::ostream& ostr, const min_h<V>& m) { return ostr << m.to_result(); Index: mln/accu/max_h.hh --- mln/accu/max_h.hh (revision 2535) +++ mln/accu/max_h.hh (working copy) @@ -67,6 +67,8 @@ const accu::histo<V>& histo() const; + void debug_print_() const; + protected: mutable accu::histo<V> h_; @@ -100,12 +102,12 @@ void max_h<V>::take(const argument& t) { - h_.take(t); - if (h_.sum() == 1) + if (h_.sum() == 0) { this->take_as_init(t); return; } + h_.take(t); if (t > t_) { ++sum_; @@ -165,25 +167,26 @@ template <typename V> inline void - max_h<V>::go_minus_() const + max_h<V>::go_plus_() const { do - --i_; - while (h_[i_] == 0); + { + ++i_; + if (h_[i_] != 0) + sum_ -= h_[i_]; + } + while (sum_ != 0); t_ = s_[i_]; } template <typename V> inline void - max_h<V>::go_plus_() const + max_h<V>::go_minus_() const { do - { - ++i_; - if (h_[i_] != 0) - sum_ -= h_[i_]; - } while (sum_ != 0); + --i_; + while (h_[i_] == 0); t_ = s_[i_]; } @@ -231,6 +234,18 @@ template <typename V> inline + void + max_h<V>::debug_print_() const + { + std::cout << "h={" << h_ << "} "; + std::cout << "sum=" << sum_ << ' ' + << "valid=" << valid_ << ' ' + << "i=" << i_ << ' ' + << "t=" << t_ << std::endl; + } + + template <typename V> + inline std::ostream& operator<<(std::ostream& ostr, const max_h<V>& m) { return ostr << m.to_result();
participants (1)
-
Thierry Geraud