X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Ftally%2Ftally.c;h=20e99dcb870dac2d56c539e6873cc1618d84d22f;hp=e166dd03c532252df2b0e31ed7d41198f390f88b;hb=e31e88bc5b7c2a018323e80f5662cf82a2c39660;hpb=6697a3dde2b3e1aa180622bd5f909bba3a8fd948 diff --git a/ccan/tally/tally.c b/ccan/tally/tally.c index e166dd03..20e99dcb 100644 --- a/ccan/tally/tally.c +++ b/ccan/tally/tally.c @@ -367,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; @@ -385,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); }