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

Special code for grouped count if there are no nils.


diffs (172 lines):

diff --git a/gdk/gdk_aggr.c b/gdk/gdk_aggr.c
--- a/gdk/gdk_aggr.c
+++ b/gdk/gdk_aggr.c
@@ -1990,8 +1990,6 @@ BATcalcavg(BAT *b, BAT *s, dbl *avg, BUN
                                if (cand == candend)                    \
                                        break;                          \
                                i = *cand++ - b->hseqbase;              \
-                               if (i >= end)                           \
-                                       break;                          \
                        } else {                                        \
                                i = start++;                            \
                                if (i == end)                           \
@@ -2003,7 +2001,7 @@ BATcalcavg(BAT *b, BAT *s, dbl *avg, BUN
                                        gid = gids[i] - min;            \
                                else                                    \
                                        gid = (oid) i;                  \
-                               if (!skip_nils || vals[i] != TYPE##_nil) { \
+                               if (vals[i] != TYPE##_nil) {            \
                                        cnts[gid]++;                    \
                                }                                       \
                        }                                               \
@@ -2043,7 +2041,7 @@ BATgroupcount(BAT *b, BAT *g, BAT *e, BA
        }
 
        if (BATcount(b) == 0 || ngrp == 0) {
-               /* trivial: no products, so return bat aligned with g
+               /* trivial: no counts, so return bat aligned with g
                 * with zero in the tail */
                lng zero = 0;
                return BATconstant(ngrp == 0 ? 0 : min, TYPE_lng, &zero, ngrp, 
TRANSIENT);
@@ -2060,62 +2058,89 @@ BATgroupcount(BAT *b, BAT *g, BAT *e, BA
        else
                gids = (const oid *) Tloc(g, start);
 
-       t = b->ttype;
-       nil = ATOMnilptr(t);
-       atomcmp = ATOMcompare(t);
-       t = ATOMbasetype(t);
-       switch (t) {
-       case TYPE_bte:
-               AGGR_COUNT(bte);
-               break;
-       case TYPE_sht:
-               AGGR_COUNT(sht);
-               break;
-       case TYPE_int:
-               AGGR_COUNT(int);
-               break;
-       case TYPE_lng:
-               AGGR_COUNT(lng);
-               break;
-#ifdef HAVE_HGE
-       case TYPE_hge:
-               AGGR_COUNT(hge);
-               break;
-#endif
-       case TYPE_flt:
-               AGGR_COUNT(flt);
-               break;
-       case TYPE_dbl:
-               AGGR_COUNT(dbl);
-               break;
-       default:
-               bi = bat_iterator(b);
-
-               for (;;) {
-                       if (cand) {
-                               if (cand == candend)
-                                       break;
-                               i = *cand++ - b->hseqbase;
-                               if (i >= end)
-                                       break;
+       if (!skip_nils || b->tnonil) {
+               /* if nils are nothing special, or if there are no
+                * nils, we don't need to look at the values at all */
+               if (cand) {
+                       if (gids) {
+                               while (cand < candend) {
+                                       i = *cand++ - b->hseqbase;
+                                       if (gids[i] >= min && gids[i] <= max)
+                                               cnts[gids[i] - min]++;
+                               }
                        } else {
-                               i = start++;
-                               if (i == end)
-                                       break;
-                       }
-                       if (gids == NULL ||
-                           (gids[i] >= min && gids[i] <= max)) {
-                               if (gids)
-                                       gid = gids[i] - min;
-                               else
-                                       gid = (oid) i;
-                               if (!skip_nils ||
-                                   (*atomcmp)(BUNtail(bi, i), nil) != 0) {
-                                       cnts[gid]++;
+                               while (cand < candend) {
+                                       i = *cand++ - b->hseqbase;
+                                       cnts[i] = 1;
                                }
                        }
+               } else {
+                       if (gids) {
+                               for (i = start; i < end; i++) {
+                                       if (gids[i] >= min && gids[i] <= max)
+                                               cnts[gids[i] - min]++;
+                               }
+                       } else {
+                               for (i = start; i < end; i++)
+                                       cnts[i] = 1;
+                       }
                }
-               break;
+       } else {
+               t = b->ttype;
+               nil = ATOMnilptr(t);
+               atomcmp = ATOMcompare(t);
+               t = ATOMbasetype(t);
+
+               switch (t) {
+               case TYPE_bte:
+                       AGGR_COUNT(bte);
+                       break;
+               case TYPE_sht:
+                       AGGR_COUNT(sht);
+                       break;
+               case TYPE_int:
+                       AGGR_COUNT(int);
+                       break;
+               case TYPE_lng:
+                       AGGR_COUNT(lng);
+                       break;
+#ifdef HAVE_HGE
+               case TYPE_hge:
+                       AGGR_COUNT(hge);
+                       break;
+#endif
+               case TYPE_flt:
+                       AGGR_COUNT(flt);
+                       break;
+               case TYPE_dbl:
+                       AGGR_COUNT(dbl);
+                       break;
+               default:
+                       bi = bat_iterator(b);
+
+                       for (;;) {
+                               if (cand) {
+                                       if (cand == candend)
+                                               break;
+                                       i = *cand++ - b->hseqbase;
+                               } else {
+                                       i = start++;
+                                       if (i == end)
+                                               break;
+                               }
+                               if (gids == NULL ||
+                                   (gids[i] >= min && gids[i] <= max)) {
+                                       if (gids)
+                                               gid = gids[i] - min;
+                                       else
+                                               gid = (oid) i;
+                                       if ((*atomcmp)(BUNtail(bi, i), nil) != 
0) {
+                                               cnts[gid]++;
+                                       }
+                               }
+                       }
+                       break;
+               }
        }
        BATsetcount(bn, ngrp);
        bn->tkey = BATcount(bn) <= 1;
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to