From 0ecc2f065bd12e8ead4e7bb05332bc3aa6bc36c7 Mon Sep 17 00:00:00 2001 From: Laurent MAZET Date: Mon, 29 Sep 2025 15:59:51 +0200 Subject: [PATCH] improve histogram --- stat.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/stat.c b/stat.c index f39d441..b7f4643 100644 --- a/stat.c +++ b/stat.c @@ -1,14 +1,15 @@ /* statistic module */ #include -#include #include #include #include #include "stat.h" -void compute_statistics (int64_t *points, int nb, int bins) +#define STEP 20 + +void compute_statistics (unsigned int *points, int nb, int bins) { printf ("Nb of points = %d\n", nb); @@ -50,7 +51,7 @@ void compute_statistics (int64_t *points, int nb, int bins) int change_done = 0; for (int i = 1; i < nb - 1; i++) { if (points[i + 1] < points[i]) { - int64_t tmp = points[i]; + unsigned int tmp = points[i]; points[i] = points[i + 1]; points[i + 1] = tmp; change_done = 1; @@ -93,6 +94,10 @@ void compute_statistics (int64_t *points, int nb, int bins) printf ("Histogram (%d)\n", nb); for (int i = 0; i < bins; i++) { + int h = (STEP * hist[i] + nb / 2 - 1) / nb; + for (int j = 0; j < STEP; j++) { + printf ("%c", (j < h) ? '#' : ' '); + } printf (" [%.2lf - %.2lf] = %d\n", min + i * gap, min + (i + 1) * gap, hist[i]); } -- 2.30.2