From 2ca94e7ac922a313984cfea0c710f18cd2000f09 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Fri, 12 Mar 2021 02:56:20 +0200 Subject: [PATCH] lib: stats_dist_get_median(), stats_dist_get_percentile() - Remove const parameter They weren't really const, because they required modifying the stats to sort them. --- src/lib/stats-dist.c | 9 ++++----- src/lib/stats-dist.h | 6 +++--- src/lib/test-stats-dist.c | 2 +- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/lib/stats-dist.c b/src/lib/stats-dist.c index 788847ae8f..882bde1a4b 100644 --- a/src/lib/stats-dist.c +++ b/src/lib/stats-dist.c @@ -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; diff --git a/src/lib/stats-dist.h b/src/lib/stats-dist.h index 82d53597af..2d49f72b68 100644 --- a/src/lib/stats-dist.h +++ b/src/lib/stats-dist.h @@ -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); } diff --git a/src/lib/test-stats-dist.c b/src/lib/test-stats-dist.c index c15082c7f7..795c22f931 100644 --- a/src/lib/test-stats-dist.c +++ b/src/lib/test-stats-dist.c @@ -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; -- 2.47.3