]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: stats_dist_get_median(), stats_dist_get_percentile() - Remove const parameter
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Fri, 12 Mar 2021 00:56:20 +0000 (02:56 +0200)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Fri, 19 Mar 2021 09:22:44 +0000 (09:22 +0000)
They weren't really const, because they required modifying the stats to sort
them.

src/lib/stats-dist.c
src/lib/stats-dist.h
src/lib/test-stats-dist.c

index 788847ae8f5e12574500bd5ff359a5697191f6f2..882bde1a4badbd13f3158c0d2dad0d9dda73a2dc 100644 (file)
@@ -108,12 +108,12 @@ static void stats_dist_ensure_sorted(struct stats_dist *stats)
        stats->sorted = TRUE;
 }
 
-uint64_t stats_dist_get_median(const struct stats_dist *stats)
+uint64_t stats_dist_get_median(struct stats_dist *stats)
 {
        if (stats->count == 0)
                return 0;
        /* cast-away const - reading requires sorting */
-       stats_dist_ensure_sorted((struct stats_dist *)stats);
+       stats_dist_ensure_sorted(stats);
        unsigned int count = (stats->count < stats->sample_count)
                ? stats->count
                : stats->sample_count;
@@ -161,12 +161,11 @@ static unsigned int stats_dist_get_index(unsigned int range, double fraction)
        return idx;
 }
 
-uint64_t stats_dist_get_percentile(const struct stats_dist *stats, double fraction)
+uint64_t stats_dist_get_percentile(struct stats_dist *stats, double fraction)
 {
        if (stats->count == 0)
                return 0;
-       /* cast-away const - reading requires sorting */
-       stats_dist_ensure_sorted((struct stats_dist *)stats);
+       stats_dist_ensure_sorted(stats);
        unsigned int count = (stats->count < stats->sample_count)
                ? stats->count
                : stats->sample_count;
index 82d53597af67d9960ee97e86da9883efa636a433..2d49f72b68c08e839932c6ed29e4280a05c54847 100644 (file)
@@ -23,14 +23,14 @@ uint64_t stats_dist_get_max(const struct stats_dist *stats);
 /* Returns events' average. */
 double stats_dist_get_avg(const struct stats_dist *stats);
 /* Returns events' approximate (through random subsampling) median. */
-uint64_t stats_dist_get_median(const struct stats_dist *stats);
+uint64_t stats_dist_get_median(struct stats_dist *stats);
 /* Returns events' variance */
 double stats_dist_get_variance(const struct stats_dist *stats);
 /* Returns events' approximate (through random subsampling) percentile.
    fraction parameter is in the range (0., 1.], so 95th %-ile is 0.95. */
-uint64_t stats_dist_get_percentile(const struct stats_dist *stats, double fraction);
+uint64_t stats_dist_get_percentile(struct stats_dist *stats, double fraction);
 /* Returns events' approximate (through random subsampling) 95th percentile. */
-static inline uint64_t stats_dist_get_95th(const struct stats_dist *stats)
+static inline uint64_t stats_dist_get_95th(struct stats_dist *stats)
 {
        return stats_dist_get_percentile(stats, 0.95);
 }
index c15082c7f71a1dfc3e3b63f20242b60541b03575..795c22f93174e5bff018c44149673b97ef959b1f 100644 (file)
@@ -8,7 +8,7 @@
 #define DBL_EQ(a, b) (fabs((a)-(b)) < 0.001)
 
 static void
-test_stats_dist_verify(const struct stats_dist *t, const int64_t *input,
+test_stats_dist_verify(struct stats_dist *t, const int64_t *input,
                       unsigned int input_size)
 {
        uint64_t min = INT_MAX, max = 0, sum = 0;