]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common/histogram: use cbits helper
authorSage Weil <sage@redhat.com>
Mon, 6 Jun 2016 21:38:42 +0000 (17:38 -0400)
committerSage Weil <sage@redhat.com>
Tue, 7 Jun 2016 17:09:48 +0000 (13:09 -0400)
Signed-off-by: Sage Weil <sage@redhat.com>
src/common/histogram.h

index 520b516eed5a2527ef52cbeeaab71fe759d29896..377e212624c0e373c2ec83875987002e01b4c17a 100644 (file)
@@ -16,6 +16,7 @@
 #include <vector>
 #include <list>
 
+#include "include/intarith.h"
 #include "include/encoding.h"
 
 namespace ceph {
@@ -59,21 +60,12 @@ public:
   }
 
   void add(int32_t v) {
-    int bin = calc_bits_of(v);
+    int bin = cbits(v);
     _expand_to(bin + 1);
     h[bin]++;
     _contract();
   }
 
-  static int calc_bits_of(int t) {
-    int b = 0;
-    while (t > 0) {
-      t = t >> 1;
-      b++;
-    }
-    return b;
-  }
-
   bool operator==(const pow2_hist_t &r) const {
     return h == r.h;
   }
@@ -89,7 +81,7 @@ public:
   int get_position_micro(int32_t v, uint64_t *lower, uint64_t *upper) {
     if (v < 0)
       return -1;
-    unsigned bin = calc_bits_of(v);
+    unsigned bin = cbits(v);
     uint64_t lower_sum = 0, upper_sum = 0, total = 0;
     for (unsigned i=0; i<h.size(); ++i) {
       if (i <= bin)