26 #ifndef MLN_ACCU_STAT_RANK_HH
27 # define MLN_ACCU_STAT_RANK_HH
37 # include <mln/accu/internal/base.hh>
38 # include <mln/accu/histo.hh>
39 # include <mln/core/concept/meta_accumulator.hh>
40 # include <mln/trait/value_.hh>
41 # include <mln/util/pix.hh>
66 explicit rank(
unsigned k);
109 template <
typename I>
struct rank< util::pix<I> >;
127 template <
typename T>
141 template <
typename T>
154 # ifndef MLN_INCLUDE_ONLY
156 template <
typename T>
165 template <
typename T>
167 rank<T>::rank(
unsigned k)
175 template <
typename T>
183 template <
typename T>
185 void rank<T>::take(
const argument& t)
198 template <
typename T>
201 rank<T>::take(
const rank<T>& other)
207 for (
unsigned i = 0; i < i_; ++i)
208 sum_minus_ += other.h_[i];
211 for (
unsigned i = i_ + 1; i < h_.nvalues(); ++i)
212 sum_plus_ += other.h_[i];
219 template <
typename T>
222 rank<T>::untake(
const argument& t)
224 mln_precondition(h_(t) != 0);
236 template <
typename T>
239 rank<T>::untake(
const rank<T>& other)
245 for (
unsigned i = 0; i < i_; ++i)
246 sum_minus_ -= other.h_[i];
249 for (
unsigned i = i_ + 1; i < h_.nvalues(); ++i)
250 sum_plus_ -= other.h_[i];
256 template <
typename T>
259 rank<T>::update_()
const
269 if ((sum_minus_ + h_[i_]) < k_)
275 if (sum_plus_ > sum_minus_)
282 template <
typename T>
285 rank<T>::go_minus_()
const
293 sum_minus_ -= h_[i_];
295 while (sum_minus_ > k_);
299 template <
typename T>
302 rank<T>::go_plus_()
const
306 sum_minus_ += h_[i_];
312 while ((sum_minus_ + h_[i_]) < k_);
316 template <
typename T>
324 i_ = (s_.index_of(mln_max(argument))
325 - s_.index_of(mln_min(argument))) / 2;
330 template <
typename T>
333 rank<T>::to_result()
const
340 template <
typename T>
343 rank<T>::is_valid()
const
348 # endif // ! MLN_INCLUDE_ONLY
356 #include <mln/accu/stat/rank_bool.hh>
358 #endif // ! MLN_ACCU_STAT_RANK_HH