From afe18d8261efd0607605f1afead3122ea9809f18 Mon Sep 17 00:00:00 2001 From: Joseph Mirabel <jmirabel@laas.fr> Date: Fri, 3 Oct 2014 10:31:14 +0200 Subject: [PATCH] Add method Statistics::find --- include/hpp/statistics/bin.hh | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/include/hpp/statistics/bin.hh b/include/hpp/statistics/bin.hh index 709fb44..7062887 100644 --- a/include/hpp/statistics/bin.hh +++ b/include/hpp/statistics/bin.hh @@ -115,6 +115,10 @@ namespace hpp { /// already in the set. virtual T& increment (const T& bin); + iterator find (const T& bin); + + template < typename U > iterator find (const U& value); + /// Return an iterator pointing at the beginning of /// the set of bins. const_iterator begin() const @@ -162,6 +166,26 @@ namespace hpp { return *it; } + template < typename T> + typename Statistics<T>::iterator Statistics <T>::find (const T& b) + { + for (iterator it = bins_.begin (); + it != bins_.end (); it++) { + if (*it < b) + continue; + if (*it == b) + return it; + break; + } + return bins_.end (); + } + + template < typename T> template < typename U > + typename Statistics<T>::iterator Statistics <T>::find (const U& v) + { + return find (T (v)); + } + template < typename T > size_t Statistics <T>::freq (const T& b) const { -- GitLab