Changeset: 9f0725a84f3e for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=9f0725a84f3e
Modified Files:
        gdk/gdk_group.c
Branch: Feb2013
Log Message:

Reuse GRPnotfound macro wherever possible.
Plus some prettifying.


diffs (248 lines):

diff --git a/gdk/gdk_group.c b/gdk/gdk_group.c
--- a/gdk/gdk_group.c
+++ b/gdk/gdk_group.c
@@ -70,13 +70,12 @@
  * At the MAL level, the multigroup function would perform the dynamic
  * optimization.
  */
-#define GRPnotfound                                                    \
+#define GRPnotfound()                                                  \
        do {                                                            \
                /* no equal found: start new group */                   \
                if (ngrp == maxgrps) {                                  \
-                       /* we need to extend extents                    \
-                        * and histo bats, do it at                     \
-                        * most once */                                 \
+                       /* we need to extend extents and histo bats, */ \
+                       /* do it at most once */                        \
                        maxgrps = BATcount(b);                          \
                        if (extents) {                                  \
                                BATsetcount(en, ngrp);                  \
@@ -99,57 +98,57 @@
 
 #define GRPhashloop(TYPE)                                              \
        do {                                                            \
-               TYPE *w = (TYPE *) Tloc(b, 0);                                  
\
+               TYPE *w = (TYPE *) Tloc(b, 0);                          \
                for (r = BUNfirst(b), p = r, q = r + BATcount(b); p < q; p++) { 
\
-                       if (gc) {                                               
\
-                               prb = hash_##TYPE(hs, &w[p]);                   
\
-                               for (hb = hs->hash[prb];                        
\
-                                    hb != BUN_NONE &&                          
\
-                                     grps[hb - r] == grps[p - r];              
\
-                                    hb = hs->link[hb]) {                       
\
-                                       if (w[p] == w[hb]) {                    
\
-                                               ngrps[p - r] = ngrps[hb - r];   
\
-                                               if (histo)                      
\
-                                                       cnts[ngrps[hb - r]]++;  
\
-                                               break;                          
\
-                                       }                                       
\
-                               }                                               
\
-                       } else if (grps) {                                      
\
-                               BUN hv = hash_##TYPE(hs, &w[p]);                
\
-                               BUN hg = hash_oid(hs, &grps[p-r]);              
\
-                               prb = ((hv << bits) ^ hg) & hs->mask;           
\
-                               for (hb = hs->hash[prb];                        
\
-                                    hb != BUN_NONE;                            
\
-                                    hb = hs->link[hb]) {                       
\
-                                       if (grps[hb - r] == grps[p - r] &&      
\
-                                           w[p] == w[hb]) {                    
\
-                                               ngrps[p - r] = ngrps[hb - r];   
\
-                                               if (histo)                      
\
-                                                       cnts[ngrps[hb - r]]++;  
\
-                                               break;                          
\
-                                       }                                       
\
-                               }                                               
\
-                       } else {                                                
\
-                               prb = hash_##TYPE(hs, &w[p]);                   
\
-                               for (hb = hs->hash[prb];                        
\
-                                    hb != BUN_NONE;                            
\
-                                    hb = hs->link[hb]) {                       
\
-                                       if (w[p] == w[hb]) {                    
\
-                                               ngrps[p - r] = ngrps[hb - r];   
\
-                                               if (histo)                      
\
-                                                       cnts[ngrps[hb - r]]++;  
\
-                                               break;                          
\
-                                       }                                       
\
-                               }                                               
\
-                       }                                                       
\
-                       if (hb == BUN_NONE ||                                   
\
-                           (gc && grps[hb - r] != grps[p - r])) {              
\
-                               GRPnotfound;                                    
\
-                               /* enter new group into hash table */           
\
-                               hs->link[p] = hs->hash[prb];                    
\
-                               hs->hash[prb] = p;                              
\
-                       }                                                       
\
-               }                                                               
\
+                       if (gc) {                                       \
+                               prb = hash_##TYPE(hs, &w[p]);           \
+                               for (hb = hs->hash[prb];                \
+                                    hb != BUN_NONE &&                  \
+                                     grps[hb - r] == grps[p - r];      \
+                                    hb = hs->link[hb]) {               \
+                                       if (w[p] == w[hb]) {            \
+                                               ngrps[p - r] = ngrps[hb - r]; \
+                                               if (histo)              \
+                                                       cnts[ngrps[hb - r]]++; \
+                                               break;                  \
+                                       }                               \
+                               }                                       \
+                       } else if (grps) {                              \
+                               BUN hv = hash_##TYPE(hs, &w[p]);        \
+                               BUN hg = hash_oid(hs, &grps[p-r]);      \
+                               prb = ((hv << bits) ^ hg) & hs->mask;   \
+                               for (hb = hs->hash[prb];                \
+                                    hb != BUN_NONE;                    \
+                                    hb = hs->link[hb]) {               \
+                                       if (grps[hb - r] == grps[p - r] && \
+                                           w[p] == w[hb]) {            \
+                                               ngrps[p - r] = ngrps[hb - r]; \
+                                               if (histo)              \
+                                                       cnts[ngrps[hb - r]]++; \
+                                               break;                  \
+                                       }                               \
+                               }                                       \
+                       } else {                                        \
+                               prb = hash_##TYPE(hs, &w[p]);           \
+                               for (hb = hs->hash[prb];                \
+                                    hb != BUN_NONE;                    \
+                                    hb = hs->link[hb]) {               \
+                                       if (w[p] == w[hb]) {            \
+                                               ngrps[p - r] = ngrps[hb - r]; \
+                                               if (histo)              \
+                                                       cnts[ngrps[hb - r]]++; \
+                                               break;                  \
+                                       }                               \
+                               }                                       \
+                       }                                               \
+                       if (hb == BUN_NONE ||                           \
+                           (gc && grps[hb - r] != grps[p - r])) {      \
+                               GRPnotfound();                          \
+                               /* enter new group into hash table */   \
+                               hs->link[p] = hs->hash[prb];            \
+                               hs->hash[prb] = p;                      \
+                       }                                               \
+               }                                                       \
        } while (0)
 
 gdk_return
@@ -352,47 +351,27 @@ BATgroup_internal(BAT **groups, BAT **ex
                if (grps)
                        prev = *grps++;
                pv = BUNtail(bi, BUNfirst(b));
-               *ngrps++ = ngrp;
+               ngrps[0] = ngrp;
+               ngrp++;
                if (extents)
-                       *exts++ = b->hseqbase;
+                       exts[0] = b->hseqbase;
                if (histo)
-                       *cnts = 1;
+                       cnts[0] = 1;
                for (r = BUNfirst(b), p = r + 1, q = r + BATcount(b);
                     p < q;
                     p++) {
                        v = BUNtail(bi, p);
                        if ((grps && *grps != prev) || cmp(pv, v) != 0) {
-                               ngrp++;
-                               if (ngrp == maxgrps) {
-                                       /* we need to extend extents
-                                        * and histo bats, do it
-                                        * once */
-                                       maxgrps = BATcount(b);
-                                       if (extents) {
-                                               BATsetcount(en, ngrp);
-                                               en = BATextend(en, maxgrps);
-                                               exts = (oid *) Tloc(en, 
BUNfirst(en) + ngrp);
-                                       }
-                                       if (histo) {
-                                               BATsetcount(hn, ngrp);
-                                               hn = BATextend(hn, maxgrps);
-                                               cnts = (wrd *) Tloc(hn, 
BUNfirst(hn) + ngrp - 1);
-                                       }
-                               }
-                               if (extents)
-                                       *exts++ = b->hseqbase + (oid) (p - r);
+                               GRPnotfound();
+                       } else {
+                               ngrps[p - r] = ngrp - 1;
                                if (histo)
-                                       *++cnts = 1;
-                       } else if (histo) {
-                               *cnts += 1;
+                                       cnts[ngrp - 1]++;
                        }
-                       *ngrps++ = ngrp;
                        pv = v;
                        if (grps)
                                prev = *grps++;
                }
-               /* ngrp is the id of the last group, turn it into the count */
-               ngrp++;
                gn->tsorted = 1;
                *groups = gn;
        } else if (b->tsorted || b->trevsorted) {
@@ -449,27 +428,7 @@ BATgroup_internal(BAT **groups, BAT **ex
                                pv = v;
                        }
                        /* start a new group */
-                       if (ngrp == maxgrps) {
-                               /* we need to extend extents and histo
-                                * bats, do it once */
-                               maxgrps = BATcount(b);
-                               if (extents) {
-                                       BATsetcount(en, ngrp);
-                                       en = BATextend(en, maxgrps);
-                                       exts = (oid *) Tloc(en, BUNfirst(en));
-                               }
-                               if (histo) {
-                                       BATsetcount(hn, ngrp);
-                                       hn = BATextend(hn, maxgrps);
-                                       cnts = (wrd *) Tloc(hn, BUNfirst(hn));
-                               }
-                       }
-                       if (extents)
-                               exts[ngrp] = b->hseqbase + (oid) (p - r);
-                       if (histo)
-                               cnts[ngrp] = 1;
-                       ngrps[p - r] = ngrp;
-                       ngrp++;
+                       GRPnotfound();
                }
        } else if (b->T->hash) {
                bit gc = g && (g->tsorted || g->trevsorted);
@@ -495,11 +454,13 @@ BATgroup_internal(BAT **groups, BAT **ex
                         * looking up (p), and that we also consider
                         * the input groups;
                         * we also exploit if g is clustered */
-                       /* skip irrelevant BUNs after the current BUNs;
-                        * exploit that hash-table links backwards through BAT 
*/
+                       /* skip irrelevant BUNs after the current
+                        * BUNs; exploit that hash-table links
+                        * backwards through BAT */
                        for (hb = hs->hash[HASHprobe(hs, v)];
                             hb != BUN_NONE && hb >= p;
-                            hb = hs->link[hb]) {}
+                            hb = hs->link[hb])
+                               ;
                        if (gc) {
                                for (;
                                     hb != BUN_NONE && grps[hb - r] == grps[p - 
r];
@@ -536,7 +497,7 @@ BATgroup_internal(BAT **groups, BAT **ex
                                }
                        }
                        if (hb == BUN_NONE || (gc && grps[hb - r] != grps[p - 
r])) {
-                               GRPnotfound;
+                               GRPnotfound();
                        }
                }
                gn->tsorted = BATcount(gn) <= 1;
@@ -657,7 +618,7 @@ BATgroup_internal(BAT **groups, BAT **ex
                                        }
                                }
                                if (hb == BUN_NONE || (gc && grps[hb - r] != 
grps[p - r])) {
-                                       GRPnotfound;
+                                       GRPnotfound();
                                        /* enter new group into hash table */
                                        hs->link[p] = hs->hash[prb];
                                        hs->hash[prb] = p;
_______________________________________________
checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to