From: Sage Weil Date: Fri, 24 Jan 2014 02:11:29 +0000 (-0800) Subject: histogram: calculate bin position of a value in the histrogram X-Git-Tag: v0.78~166^2~43 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=8b68ad037f1607d75909584402217a502b44dc2b;p=ceph.git histogram: calculate bin position of a value in the histrogram Generate a lower and upper bound. Signed-off-by: Sage Weil --- diff --git a/src/include/histogram.h b/src/include/histogram.h index c817b1ec175a..73ddd5d289b5 100644 --- a/src/include/histogram.h +++ b/src/include/histogram.h @@ -48,6 +48,39 @@ public: h[bin] = v; _contract(); } + static int calc_bits_of(int t) { + int b = 0; + while (t > 0) { + t = t >> 1; + b++; + } + return b; + } + + /// get a value's position in the histogram. + /// + /// positions are represented as values in the range [0..1000000] + /// (millionths on the unit interval). + /// + /// @param v [in] value (non-negative) + /// @param lower [out] pointer to lower-bound (0..1000000) + /// @param upper [out] pointer to the upper bound (0..1000000) + int get_position_micro(int32_t v, unsigned *lower, unsigned *upper) { + if (v < 0) + return -ERANGE; + unsigned bin = calc_bits_of(v); + unsigned lower_sum = 0, upper_sum = 0, total = 0; + for (unsigned i=0; i