From owner-svn-src-all@freebsd.org Mon Feb 3 20:46:31 2020 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id C36C322E5E8; Mon, 3 Feb 2020 20:46:31 +0000 (UTC) (envelope-from phk@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 48BKcR4stVz46rW; Mon, 3 Feb 2020 20:46:31 +0000 (UTC) (envelope-from phk@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id A24DD69B4; Mon, 3 Feb 2020 20:46:31 +0000 (UTC) (envelope-from phk@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 013KkVwg021857; Mon, 3 Feb 2020 20:46:31 GMT (envelope-from phk@FreeBSD.org) Received: (from phk@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 013KkVj4021856; Mon, 3 Feb 2020 20:46:31 GMT (envelope-from phk@FreeBSD.org) Message-Id: <202002032046.013KkVj4021856@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: phk set sender to phk@FreeBSD.org using -f From: Poul-Henning Kamp Date: Mon, 3 Feb 2020 20:46:31 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r357465 - head/usr.bin/ministat X-SVN-Group: head X-SVN-Commit-Author: phk X-SVN-Commit-Paths: head/usr.bin/ministat X-SVN-Commit-Revision: 357465 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 03 Feb 2020 20:46:31 -0000 Author: phk Date: Mon Feb 3 20:46:31 2020 New Revision: 357465 URL: https://svnweb.freebsd.org/changeset/base/357465 Log: Minor cleanups to allow handing vast datasets. Submitted by: dds Modified: head/usr.bin/ministat/ministat.c Modified: head/usr.bin/ministat/ministat.c ============================================================================== --- head/usr.bin/ministat/ministat.c Mon Feb 3 19:36:24 2020 (r357464) +++ head/usr.bin/ministat/ministat.c Mon Feb 3 20:46:31 2020 (r357465) @@ -142,9 +142,9 @@ static char symbol[MAX_DS] = { ' ', 'x', '+', '*', '%' struct dataset { char *name; double *points; - unsigned lpoints; + size_t lpoints; double sy, syy; - unsigned n; + size_t n; }; static struct dataset * @@ -202,7 +202,7 @@ Avg(const struct dataset *ds) static double Median(const struct dataset *ds) { - const unsigned m = ds->n / 2; + const size_t m = ds->n / 2; if ((ds->n % 2) == 0) return ((ds->points[m] + (ds->points[m - 1])) / 2); @@ -212,13 +212,13 @@ Median(const struct dataset *ds) static double Var(struct dataset *ds) { - unsigned n; + size_t z; const double a = Avg(ds); if (isnan(ds->syy)) { ds->syy = 0.0; - for (n = 0; n < ds->n; n++) - ds->syy += (ds->points[n] - a) * (ds->points[n] - a); + for (z = 0; z < ds->n; z++) + ds->syy += (ds->points[z] - a) * (ds->points[z] - a); } return (ds->syy / (ds->n - 1.0)); @@ -242,7 +242,7 @@ static void Vitals(struct dataset *ds, int flag) { - printf("%c %3d %13.8g %13.8g %13.8g %13.8g %13.8g", symbol[flag], + printf("%c %3zu %13.8g %13.8g %13.8g %13.8g %13.8g", symbol[flag], ds->n, Min(ds), Max(ds), Median(ds), Avg(ds), Stddev(ds)); printf("\n"); } @@ -252,13 +252,13 @@ Relative(struct dataset *ds, struct dataset *rs, int c { double spool, s, d, e, t; double re; - int i; + size_t z; - i = ds->n + rs->n - 2; - if (i > NSTUDENT) + z = ds->n + rs->n - 2; + if (z > NSTUDENT) t = student[0][confidx]; else - t = student[i][confidx]; + t = student[z][confidx]; spool = (ds->n - 1) * Var(ds) + (rs->n - 1) * Var(rs); spool /= ds->n + rs->n - 2; spool = sqrt(spool); @@ -272,7 +272,6 @@ Relative(struct dataset *ds, struct dataset *rs, int c re = t * sqrt(re); if (fabs(d) > e) { - printf("Difference at %.1f%% confidence\n", studentpct[confidx]); printf(" %g +/- %g\n", d, e); printf(" %g%% +/- %g%%\n", d * 100 / Avg(rs), re * 100 / Avg(rs)); @@ -290,7 +289,7 @@ struct plot { int width; double x0, dx; - int height; + size_t height; char *data; char **bar; int separate_bars; @@ -343,9 +342,11 @@ static void PlotSet(struct dataset *ds, int val) { struct plot *pl; - int i, j, m, x; - unsigned n; + int i, x; + size_t m, j, z; + size_t n; int bar; + double av, sd; pl = &plot; if (pl->span == 0) @@ -370,6 +371,7 @@ PlotSet(struct dataset *ds, int val) m = 1; i = -1; j = 0; + /* Set m to max(j) + 1, to allocate required memory */ for (n = 0; n < ds->n; n++) { x = (ds->points[n] - pl->x0) / pl->dx; if (x == i) { @@ -400,18 +402,20 @@ PlotSet(struct dataset *ds, int val) } pl->data[j * pl->width + x] |= val; } - if (!isnan(Stddev(ds))) { - x = ((Avg(ds) - Stddev(ds)) - pl->x0) / pl->dx; - m = ((Avg(ds) + Stddev(ds)) - pl->x0) / pl->dx; + av = Avg(ds); + sd = Stddev(ds); + if (!isnan(sd)) { + x = ((av - sd) - pl->x0) / pl->dx; + m = ((av + sd) - pl->x0) / pl->dx; pl->bar[bar][m] = '|'; pl->bar[bar][x] = '|'; - for (i = x + 1; i < m; i++) - if (pl->bar[bar][i] == 0) - pl->bar[bar][i] = '_'; + for (z = x + 1; z < m; z++) + if (pl->bar[bar][z] == 0) + pl->bar[bar][z] = '_'; } x = (Median(ds) - pl->x0) / pl->dx; pl->bar[bar][x] = 'M'; - x = (Avg(ds) - pl->x0) / pl->dx; + x = (av - pl->x0) / pl->dx; pl->bar[bar][x] = 'A'; } @@ -420,6 +424,7 @@ DumpPlot(void) { struct plot *pl; int i, j, k; + size_t z; pl = &plot; if (pl->span == 0) { @@ -432,10 +437,10 @@ DumpPlot(void) putchar('-'); putchar('+'); putchar('\n'); - for (i = 1; i < pl->height; i++) { + for (z = 1; z < pl->height; z++) { putchar('|'); for (j = 0; j < pl->width; j++) { - k = pl->data[(pl->height - i) * pl->width + j]; + k = pl->data[(pl->height - z) * pl->width + j]; if (k >= 0 && k < MAX_DS) putchar(symbol[k]); else