]> git.ozlabs.org Git - ccan/blobdiff - ccan/tally/tally.c
tally: Adapt get_max_bucket to Samba coding conventions
[ccan] / ccan / tally / tally.c
index d9f30ba12f39cc87c94d2e0e12c4af23177b8add..b1bc70b8dbeb7350dcfca63767fea4abbee6ef71 100644 (file)
@@ -292,26 +292,28 @@ static int64_t divls64(int64_t u1, uint64_t u0, int64_t v)
 {
        int64_t q, uneg, vneg, diff, borrow;
 
-       uneg = u1 >> 63;          // -1 if u < 0.
-       if (uneg) {               // Compute the absolute
-               u0 = -u0;         // value of the dividend u.
+       uneg = u1 >> 63;          /* -1 if u < 0. */
+       if (uneg) {               /* Compute the absolute */
+               u0 = -u0;         /* value of the dividend u. */
                borrow = (u0 != 0);
                u1 = -u1 - borrow;
        }
 
-       vneg = v >> 63;           // -1 if v < 0.
-       v = (v ^ vneg) - vneg;    // Absolute value of v.
+       vneg = v >> 63;           /* -1 if v < 0. */
+       v = (v ^ vneg) - vneg;    /* Absolute value of v. */
 
-       if ((uint64_t)u1 >= (uint64_t)v)
+       if ((uint64_t)u1 >= (uint64_t)v) {
                goto overflow;
+       }
 
        q = divlu64(u1, u0, v);
 
-       diff = uneg ^ vneg;       // Negate q if signs of
-       q = (q ^ diff) - diff;    // u and v differed.
+       diff = uneg ^ vneg;       /* Negate q if signs of */
+       q = (q ^ diff) - diff;    /* u and v differed. */
 
-       if ((diff ^ q) < 0 && q != 0) {    // If overflow, return the largest
-       overflow:                          // possible neg. quotient.
+       if ((diff ^ q) < 0 && q != 0) {    /* If overflow, return the
+                                             largest */
+       overflow:                          /* possible neg. quotient. */
                q = 0x8000000000000000ULL;
        }
        return q;
@@ -320,8 +322,9 @@ static int64_t divls64(int64_t u1, uint64_t u0, int64_t v)
 ssize_t tally_mean(const struct tally *tally)
 {
        size_t count = tally_num(tally);
-       if (!count)
+       if (!count) {
                return 0;
+       }
 
        if (sizeof(tally->total[0]) == sizeof(uint32_t)) {
                /* Use standard 64-bit arithmetic. */
@@ -364,10 +367,11 @@ static ssize_t bucket_range(const struct tally *tally, unsigned b, size_t *err)
        ssize_t min, max;
 
        min = bucket_min(tally->min, tally->step_bits, b);
-       if (b == tally->buckets - 1)
+       if (b == tally->buckets - 1) {
                max = tally->max;
-       else
+       } else {
                max = bucket_min(tally->min, tally->step_bits, b+1) - 1;
+       }
 
        /* FIXME: Think harder about cumulative error; is this enough?. */
        *err = (max - min + 1) / 2;
@@ -382,8 +386,9 @@ ssize_t tally_approx_median(const struct tally *tally, size_t *err)
 
        for (i = 0; i < tally->buckets; i++) {
                total += tally->counts[i];
-               if (total * 2 >= count)
+               if (total * 2 >= count) {
                        break;
+               }
        }
        return bucket_range(tally, i, err);
 }
@@ -417,9 +422,11 @@ static unsigned get_max_bucket(const struct tally *tally)
 {
        unsigned int i;
 
-       for (i = tally->buckets; i > 0; i--)
-               if (tally->counts[i-1])
+       for (i = tally->buckets; i > 0; i--) {
+               if (tally->counts[i-1]) {
                        break;
+               }
+       }
        return i;
 }