26 #ifndef MLN_ACCU_STAT_MAX_H_HH
27 # define MLN_ACCU_STAT_MAX_H_HH
33 # include <mln/accu/internal/base.hh>
34 # include <mln/core/concept/meta_accumulator.hh>
35 # include <mln/accu/histo.hh>
36 # include <mln/util/pix.hh>
45 template <
typename V>
struct max_h;
56 struct accumulator_< accu::stat::max_h<V> >
58 typedef accumulator::has_untake::yes has_untake;
59 typedef accumulator::has_set_value::no has_set_value;
60 typedef accumulator::has_stop::no has_stop;
61 typedef accumulator::when_pix::use_v when_pix;
100 struct max_h :
public mln::accu::internal::base< const V&, max_h<V> >
109 void take(
const argument& t);
110 void take_as_init_(
const argument& t);
112 void untake(
const argument& t);
115 unsigned card()
const {
return h_.sum(); }
126 void debug_print_()
const;
133 mutable unsigned sum_;
144 void update_()
const;
145 void go_minus_()
const;
146 void go_plus_()
const;
148 void invariant_()
const;
152 template <
typename I>
struct max_h< util::pix<I> >;
154 # ifndef MLN_INCLUDE_ONLY
156 template <typename V>
159 max_h<V>::invariant_() const
162 mln_invariant(! valid_ || (sum_ == 0));
165 template <
typename V>
175 template <
typename V>
178 max_h<V>::take(
const argument& t)
182 this->take_as_init_(t);
194 template <
typename V>
197 max_h<V>::take(
const max_h<V>& other)
201 for (
unsigned i = this->card() - 1; i > i_; --i)
203 if (valid_ && sum_ != 0)
209 template <
typename V>
212 max_h<V>::untake(
const argument& t)
214 mln_precondition(h_(t) != 0);
223 mln_invariant(sum_ >= 1);
228 if (t == t_ && h_[i_] == 0)
233 template <
typename V>
236 max_h<V>::update_()
const
245 mln_postcondition(sum_ == 0);
246 mln_postcondition(h_[i_] != 0);
247 for (
unsigned j = i_ + 1; j < h_.nvalues(); ++j)
248 mln_postcondition(h_[j] == 0);
251 template <
typename V>
254 max_h<V>::go_plus_()
const
266 template <
typename V>
269 max_h<V>::go_minus_()
const
277 template <
typename V>
284 i_ = mln_min(argument);
289 template <
typename V>
301 template <
typename V>
303 const typename max_h<V>::argument&
312 template <
typename V>
320 template <
typename V>
328 template <
typename V>
333 std::cout <<
"h={" << h_ <<
"} h.sum = " << h_.sum() <<
' ';
334 std::cout <<
"sum=" << sum_ <<
' '
335 <<
"valid=" << valid_ <<
' '
337 <<
"t=" << t_ << std::endl;
340 template <
typename V>
342 std::ostream& operator<<(std::ostream& ostr, const max_h<V>& m)
347 # endif // ! MLN_INCLUDE_ONLY
356 #endif // ! MLN_ACCU_STAT_MAX_H_HH