Changeset: 7082e38195c2 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=7082e38195c2
Modified Files:
        gdk/gdk_aggr.c
Branch: Mar2018
Log Message:

Use bool.


diffs (truncated from 457 to 300 lines):

diff --git a/gdk/gdk_aggr.c b/gdk/gdk_aggr.c
--- a/gdk/gdk_aggr.c
+++ b/gdk/gdk_aggr.c
@@ -147,7 +147,7 @@ BATgroupaggrinit(BAT *b, BAT *g, BAT *e,
 /* ---------------------------------------------------------------------- */
 /* sum */
 
-static inline int
+static inline bool
 samesign(double x, double y)
 {
        return (x >= 0) == (y >= 0);
@@ -182,13 +182,13 @@ static BUN
 dofsum(const void *restrict values, oid seqb, BUN start, BUN end,
        void *restrict results, BUN ngrp, int tp1, int tp2,
        const oid *restrict cand, const oid *candend, const oid *restrict gids,
-       oid min, oid max, int skip_nils, int abort_on_error,
-       int nil_if_empty, const char *func)
+       oid min, oid max, bool skip_nils, bool abort_on_error,
+       bool nil_if_empty, const char *func)
 {
        struct pergroup {
                int npartials;
                int maxpartials;
-               int valseen;
+               bool valseen;
 #ifdef INFINITES_ALLOWED
                float infs;
 #else
@@ -224,7 +224,7 @@ dofsum(const void *restrict values, oid 
                return BUN_NONE;
        for (grp = 0; grp < ngrp; grp++) {
                pergroup[grp].npartials = 0;
-               pergroup[grp].valseen = 0;
+               pergroup[grp].valseen = false;
                pergroup[grp].maxpartials = 2;
                pergroup[grp].infs = 0;
                pergroup[grp].partials = GDKmalloc(pergroup[grp].maxpartials * 
sizeof(double));
@@ -268,7 +268,7 @@ dofsum(const void *restrict values, oid 
                        }
                        continue;
                }
-               pergroup[grp].valseen = 1;
+               pergroup[grp].valseen = true;
 #ifdef INFINITES_ALLOWED
                if (isinf(x)) {
                        pergroup[grp].infs += x;
@@ -476,7 +476,7 @@ dofsum(const void *restrict values, oid 
                                                       goto overflow);  \
                                }                                       \
                        } else {                                        \
-                               int seenval = 0;                        \
+                               bool seenval = false;                   \
                                for (i = start; i < end && nils == 0; i++) { \
                                        x = vals[i];                    \
                                        if (is_##TYPE1##_nil(x)) {      \
@@ -490,7 +490,7 @@ dofsum(const void *restrict values, oid 
                                                               TYPE2, sum, \
                                                               
GDK_##TYPE2##_max, \
                                                               goto overflow); \
-                                               seenval = 1;            \
+                                               seenval = true;         \
                                        }                               \
                                }                                       \
                                *seen = seenval;                        \
@@ -500,7 +500,7 @@ dofsum(const void *restrict values, oid 
                } else if (ngrp == 1) {                                 \
                        /* single group, with candidate list */         \
                        TYPE2 sum;                                      \
-                       int seenval = 0;                                \
+                       bool seenval = false;                           \
                        ALGODEBUG fprintf(stderr,                       \
                                          "#%s: with candidates, no groups; " \
                                          "start " BUNFMT ", end " BUNFMT \
@@ -523,7 +523,7 @@ dofsum(const void *restrict values, oid 
                                                       TYPE2, sum,      \
                                                       GDK_##TYPE2##_max, \
                                                       goto overflow);  \
-                                       seenval = 1;                    \
+                                       seenval = true;                 \
                                }                                       \
                        }                                               \
                        if (seenval)                                    \
@@ -609,11 +609,11 @@ dofsum(const void *restrict values, oid 
        } while (0)
 
 static BUN
-dosum(const void *restrict values, int nonil, oid seqb, BUN start, BUN end,
+dosum(const void *restrict values, bool nonil, oid seqb, BUN start, BUN end,
       void *restrict results, BUN ngrp, int tp1, int tp2,
       const oid *restrict cand, const oid *candend, const oid *restrict gids,
-      oid min, oid max, int skip_nils, int abort_on_error,
-      int nil_if_empty, const char *func)
+      oid min, oid max, bool skip_nils, bool abort_on_error,
+      bool nil_if_empty, const char *func)
 {
        BUN nils = 0;
        BUN i;
@@ -810,7 +810,7 @@ BATgroupsum(BAT *b, BAT *g, BAT *e, BAT 
        nils = dosum(Tloc(b, 0), b->tnonil, b->hseqbase, start, end,
                     Tloc(bn, 0), ngrp, b->ttype, tp,
                     cand, candend, gids, min, max,
-                    skip_nils, abort_on_error, 1, "BATgroupsum");
+                    skip_nils, abort_on_error, true, "BATgroupsum");
 
        if (nils < BUN_NONE) {
                BATsetcount(bn, ngrp);
@@ -936,7 +936,7 @@ BATsum(void *res, int tp, BAT *b, BAT *s
        if (BATcount(b) == 0)
                return GDK_SUCCEED;
        nils = dosum(Tloc(b, 0), b->tnonil, b->hseqbase, start, end,
-                    res, 1, b->ttype, tp, cand, candend, &min, min, max,
+                    res, true, b->ttype, tp, cand, candend, &min, min, max,
                     skip_nils, abort_on_error, nil_if_empty, "BATsum");
        return nils < BUN_NONE ? GDK_SUCCEED : GDK_FAIL;
 }
@@ -947,8 +947,7 @@ BATsum(void *res, int tp, BAT *b, BAT *s
 #define AGGR_PROD(TYPE1, TYPE2, TYPE3)                                 \
        do {                                                            \
                const TYPE1 *restrict vals = (const TYPE1 *) values;    \
-               assert(gidincr == 0 || gidincr == 1);                   \
-               gid = 0;        /* doesn't change if gidincr == 0 */    \
+               gid = 0;        /* doesn't change if gidincr == false */ \
                for (;;) {                                              \
                        if (cand) {                                     \
                                if (cand == candend)                    \
@@ -961,7 +960,7 @@ BATsum(void *res, int tp, BAT *b, BAT *s
                                if (i == end)                           \
                                        break;                          \
                        }                                               \
-                       if (gids == NULL || gidincr == 0 ||             \
+                       if (gids == NULL || !gidincr ||                 \
                            (gids[i] >= min && gids[i] <= max)) {       \
                                if (gidincr) {                          \
                                        if (gids)                       \
@@ -998,8 +997,7 @@ BATsum(void *res, int tp, BAT *b, BAT *s
 #define AGGR_PROD_HGE(TYPE)                                            \
        do {                                                            \
                const TYPE *vals = (const TYPE *) values;               \
-               assert(gidincr == 0 || gidincr == 1);                   \
-               gid = 0;        /* doesn't change if gidincr == 0 */    \
+               gid = 0;        /* doesn't change if gidincr == false */ \
                for (;;) {                                              \
                        if (cand) {                                     \
                                if (cand == candend)                    \
@@ -1012,7 +1010,7 @@ BATsum(void *res, int tp, BAT *b, BAT *s
                                if (i == end)                           \
                                        break;                          \
                        }                                               \
-                       if (gids == NULL || gidincr == 0 ||             \
+                       if (gids == NULL || !gidincr ||                 \
                            (gids[i] >= min && gids[i] <= max)) {       \
                                if (gidincr) {                          \
                                        if (gids)                       \
@@ -1044,8 +1042,7 @@ BATsum(void *res, int tp, BAT *b, BAT *s
 #define AGGR_PROD_LNG(TYPE)                                            \
        do {                                                            \
                const TYPE *restrict vals = (const TYPE *) values;      \
-               assert(gidincr == 0 || gidincr == 1);                   \
-               gid = 0;        /* doesn't change if gidincr == 0 */    \
+               gid = 0;        /* doesn't change if gidincr == false */ \
                for (;;) {                                              \
                        if (cand) {                                     \
                                if (cand == candend)                    \
@@ -1058,7 +1055,7 @@ BATsum(void *res, int tp, BAT *b, BAT *s
                                if (i == end)                           \
                                        break;                          \
                        }                                               \
-                       if (gids == NULL || gidincr == 0 ||             \
+                       if (gids == NULL || !gidincr ||                 \
                            (gids[i] >= min && gids[i] <= max)) {       \
                                if (gidincr) {                          \
                                        if (gids)                       \
@@ -1094,8 +1091,7 @@ BATsum(void *res, int tp, BAT *b, BAT *s
 #define AGGR_PROD_FLOAT(TYPE1, TYPE2)                                  \
        do {                                                            \
                const TYPE1 *restrict vals = (const TYPE1 *) values;    \
-               assert(gidincr == 0 || gidincr == 1);                   \
-               gid = 0;        /* doesn't change if gidincr == 0 */    \
+               gid = 0;        /* doesn't change if gidincr == false */ \
                for (;;) {                                              \
                        if (cand) {                                     \
                                if (cand == candend)                    \
@@ -1108,7 +1104,7 @@ BATsum(void *res, int tp, BAT *b, BAT *s
                                if (i == end)                           \
                                        break;                          \
                        }                                               \
-                       if (gids == NULL || gidincr == 0 ||             \
+                       if (gids == NULL || !gidincr ||                 \
                            (gids[i] >= min && gids[i] <= max)) {       \
                                if (gidincr) {                          \
                                        if (gids)                       \
@@ -1146,8 +1142,8 @@ BATsum(void *res, int tp, BAT *b, BAT *s
 static BUN
 doprod(const void *restrict values, oid seqb, BUN start, BUN end, void 
*restrict results,
        BUN ngrp, int tp1, int tp2, const oid *restrict cand, const oid 
*candend,
-       const oid *restrict gids, int gidincr, oid min, oid max,
-       int skip_nils, int abort_on_error, int nil_if_empty, const char *func)
+       const oid *restrict gids, bool gidincr, oid min, oid max,
+       bool skip_nils, bool abort_on_error, bool nil_if_empty, const char 
*func)
 {
        BUN nils = 0;
        BUN i;
@@ -1412,8 +1408,8 @@ BATgroupprod(BAT *b, BAT *g, BAT *e, BAT
 
        nils = doprod(Tloc(b, 0), b->hseqbase, start, end,
                      Tloc(bn, 0), ngrp, b->ttype, tp,
-                     cand, candend, gids, 1, min, max,
-                     skip_nils, abort_on_error, 1, "BATgroupprod");
+                     cand, candend, gids, true, min, max,
+                     skip_nils, abort_on_error, true, "BATgroupprod");
 
        if (nils < BUN_NONE) {
                BATsetcount(bn, ngrp);
@@ -1476,8 +1472,8 @@ BATprod(void *res, int tp, BAT *b, BAT *
        }
        if (BATcount(b) == 0)
                return GDK_SUCCEED;
-       nils = doprod(Tloc(b, 0), b->hseqbase, start, end, res, 1,
-                     b->ttype, tp, cand, candend, &min, 0, min, max,
+       nils = doprod(Tloc(b, 0), b->hseqbase, start, end, res, true,
+                     b->ttype, tp, cand, candend, &min, false, min, max,
                      skip_nils, abort_on_error, nil_if_empty, "BATprod");
        return nils < BUN_NONE ? GDK_SUCCEED : GDK_FAIL;
 }
@@ -1786,8 +1782,8 @@ BATgroupavg(BAT **bnp, BAT **cntsp, BAT 
                cn->tkey = BATcount(cn) <= 1;
                cn->tsorted = BATcount(cn) <= 1;
                cn->trevsorted = BATcount(cn) <= 1;
-               cn->tnil = 0;
-               cn->tnonil = 1;
+               cn->tnil = false;
+               cn->tnonil = true;
                *cntsp = cn;
        }
        BATsetcount(bn, ngrp);
@@ -1935,7 +1931,7 @@ BATcalcavg(BAT *b, BAT *s, dbl *avg, BUN
        const oid *cand = NULL, *candend = NULL;
        const void *restrict src;
        /* these two needed for ADD_WITH_CHECK macro */
-       int abort_on_error = 1;
+       bool abort_on_error = true;
        BUN nils = 0;
 
        CANDINIT(b, s, start, end, cnt, cand, candend);
@@ -2143,8 +2139,8 @@ BATgroupcount(BAT *b, BAT *g, BAT *e, BA
        bn->tkey = BATcount(bn) <= 1;
        bn->tsorted = BATcount(bn) <= 1;
        bn->trevsorted = BATcount(bn) <= 1;
-       bn->tnil = 0;
-       bn->tnonil = 1;
+       bn->tnil = false;
+       bn->tnonil = true;
        return bn;
 }
 
@@ -2221,8 +2217,8 @@ BATgroupsize(BAT *b, BAT *g, BAT *e, BAT
        bn->tkey = BATcount(bn) <= 1;
        bn->tsorted = BATcount(bn) <= 1;
        bn->trevsorted = BATcount(bn) <= 1;
-       bn->tnil = 0;
-       bn->tnonil = 1;
+       bn->tnil = false;
+       bn->tnonil = true;
        return bn;
 }
 
@@ -2294,7 +2290,7 @@ static BUN
 do_groupmin(oid *restrict oids, BAT *b, const oid *restrict gids, BUN ngrp,
            oid min, oid max, BUN start, BUN end,
            const oid *restrict cand, const oid *candend,
-           BUN cnt, int skip_nils, int gdense)
+           BUN cnt, bool skip_nils, bool gdense)
 {
        oid gid;
        BUN i, nils;
@@ -2419,7 +2415,7 @@ static BUN
 do_groupmax(oid *restrict oids, BAT *b, const oid *restrict gids, BUN ngrp,
            oid min, oid max, BUN start, BUN end,
            const oid *restrict cand, const oid *candend,
-           BUN cnt, int skip_nils, int gdense)
+           BUN cnt, bool skip_nils, bool gdense)
 {
        oid gid;
        BUN i, nils;
@@ -2538,11 +2534,11 @@ do_groupmax(oid *restrict oids, BAT *b, 
 }
 
 static BAT *
-BATgroupminmax(BAT *b, BAT *g, BAT *e, BAT *s, int tp, int skip_nils,
-              int abort_on_error,
+BATgroupminmax(BAT *b, BAT *g, BAT *e, BAT *s, int tp, bool skip_nils,
+              bool abort_on_error,
               BUN (*minmax)(oid *restrict, BAT *, const oid *restrict, BUN,
                             oid, oid, BUN, BUN, const oid *restrict,
-                            const oid *, BUN, int, int),
+                            const oid *, BUN, bool, bool),
               const char *name)
 {
        const oid *restrict gids;
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to