Changeset: a4321fe6f844 for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=a4321fe6f844 Modified Files: gdk/gdk_group.c Branch: Feb2013 Log Message:
type-expanded all subgroup code,
mainly to avoid BUNtail() and cmp() calls in BATloops
diffs (truncated from 581 to 300 lines):
diff --git a/gdk/gdk_group.c b/gdk/gdk_group.c
--- a/gdk/gdk_group.c
+++ b/gdk/gdk_group.c
@@ -70,6 +70,7 @@
* At the MAL level, the multigroup function would perform the dynamic
* optimization.
*/
+
#define GRPnotfound() \
do { \
/* no equal found: start new group */ \
@@ -96,11 +97,184 @@
ngrp++; \
} while (0)
-#define GRPhashloop(TYPE) \
+
+#define GRP_compare_consecutive_values(INIT_0,INIT_1,COMP,KEEP)
\
do { \
- TYPE *w = (TYPE *) Tloc(b, 0); \
- for (r = BUNfirst(b), p = r, q = r + BATcount(b); p < q; p++) {
\
- prb = hash_##TYPE(hs, &w[p]); \
+ INIT_0; \
+ for (r = BUNfirst(b), p = r + 1, q = r + BATcount(b); \
+ p < q; \
+ p++) { \
+ INIT_1; \
+ if ((grps && *grps != prev) || COMP) { \
+ GRPnotfound(); \
+ } else { \
+ ngrps[p - r] = ngrp - 1; \
+ if (histo) \
+ cnts[ngrp - 1]++; \
+ } \
+ KEEP; \
+ if (grps) \
+ prev = *grps++; \
+ } \
+ } while(0)
+
+#define GRP_compare_consecutive_values_tpe(TYPE) \
+ GRP_compare_consecutive_values( \
+ /* INIT_0 */ TYPE *w = (TYPE *) Tloc(b, 0); \
+ TYPE pw = w[BUNfirst(b)] , \
+ /* INIT_1 */ , \
+ /* COMP */ w[p] != pw , \
+ /* KEEP */ pw = w[p] \
+ )
+
+#define GRP_compare_consecutive_values_any() \
+ GRP_compare_consecutive_values( \
+ /* INIT_0 */ pv = BUNtail(bi, BUNfirst(b)) , \
+ /* INIT_1 */ v = BUNtail(bi, p) , \
+ /* COMP */ cmp(v, pv) != 0 , \
+ /* KEEP */ pv = v \
+ )
+
+
+#define GRP_subscan_old_groups(INIT_0,INIT_1,COMP,KEEP)
\
+ do { \
+ INIT_0; \
+ pgrp[grps[0]] = BUNfirst(b); \
+ for (j = r = BUNfirst(b), p = r + 1, q = r + BATcount(b); \
+ p < q; \
+ p++) { \
+ INIT_1; \
+ if (COMP) { \
+ /* range [j, p) is all same value */ \
+ /* i is position where we saw p's old \
+ * group last */ \
+ i = pgrp[grps[p - r]]; \
+ /* p is new position where we saw this \
+ * group */ \
+ pgrp[grps[p - r]] = p; \
+ if (j <= i && i < p) { \
+ /* i is position of equal \
+ * value in same old group as \
+ * p, so p gets same new group \
+ * as i */ \
+ oid grp = ngrps[i - r]; \
+ ngrps[p - r] = grp; \
+ if (histo) \
+ cnts[grp]++; \
+ if (gn->tsorted && \
+ grp != ngrp - 1) \
+ gn->tsorted = 0; \
+ /* we found the value/group \
+ * combination, go to next \
+ * value */ \
+ continue; \
+ } \
+ } else { \
+ /* value differs from previous value */ \
+ j = p; \
+ KEEP; \
+ pgrp[grps[p - r]] = p; \
+ } \
+ /* start a new group */ \
+ GRPnotfound(); \
+ } \
+ } while(0)
+
+#define GRP_subscan_old_groups_tpe(TYPE) \
+ GRP_subscan_old_groups( \
+ /* INIT_0 */ TYPE *w = (TYPE *) Tloc(b, 0); \
+ TYPE pw = w[BUNfirst(b)] , \
+ /* INIT_1 */ , \
+ /* COMP */ w[p] == pw , \
+ /* KEEP */ pw = w[p] \
+ )
+
+#define GRP_subscan_old_groups_any() \
+ GRP_subscan_old_groups( \
+ /* INIT_0 */ pv = BUNtail(bi, BUNfirst(b)) , \
+ /* INIT_1 */ v = BUNtail(bi, p) , \
+ /* COMP */ cmp(v, pv) == 0 , \
+ /* KEEP */ pv = v \
+ )
+
+
+#define GRP_use_existing_hash_table(INIT_0,INIT_1,HASH,COMP) \
+ do { \
+ INIT_0; \
+ for (r = BUNfirst(b), p = r, q = r + BATcount(b); \
+ p < q; \
+ p++) { \
+ INIT_1; \
+ /* this loop is similar, but not equal, to \
+ * HASHloop: the difference is that we only \
+ * consider BUNs smaller than the one we're \
+ * looking up (p), and that we also consider \
+ * the input groups */ \
+ if (grps) { \
+ for (hb = hs->hash[HASH]; \
+ hb != BUN_NONE; \
+ hb = hs->link[hb]) { \
+ if (hb < p && \
+ grps[hb - r] == grps[p - r] && \
+ COMP) { \
+ oid grp = ngrps[hb - r]; \
+ ngrps[p - r] = grp; \
+ if (histo) \
+ cnts[grp]++; \
+ if (gn->tsorted && \
+ grp != ngrp - 1) \
+ gn->tsorted = 0; \
+ break; \
+ } \
+ } \
+ } else { \
+ for (hb = hs->hash[HASH]; \
+ hb != BUN_NONE; \
+ hb = hs->link[hb]) { \
+ if (hb < p && \
+ COMP) { \
+ oid grp = ngrps[hb - r]; \
+ ngrps[p - r] = grp; \
+ if (histo) \
+ cnts[grp]++; \
+ if (gn->tsorted && \
+ grp != ngrp - 1) \
+ gn->tsorted = 0; \
+ break; \
+ } \
+ } \
+ } \
+ if (hb == BUN_NONE) { \
+ GRPnotfound(); \
+ } \
+ } \
+ } while(0)
+
+#define GRP_use_existing_hash_table_tpe(TYPE) \
+ GRP_use_existing_hash_table( \
+ /* INIT_0 */ TYPE *w = (TYPE *) Tloc(b, 0) , \
+ /* INIT_1 */ , \
+ /* HASH */ hash_##TYPE(hs, &w[p]) , \
+ /* COMP */ w[p] == w[hb] \
+ )
+
+#define GRP_use_existing_hash_table_any() \
+ GRP_use_existing_hash_table( \
+ /* INIT_0 */ , \
+ /* INIT_1 */ v = BUNtail(bi, p) , \
+ /* HASH */ hash_any(hs, v) , \
+ /* COMP */ cmp(v, BUNtail(bi, hb)) == 0 \
+ )
+
+
+#define GRP_create_partial_hash_table(INIT_0,INIT_1,HASH,COMP) \
+ do { \
+ INIT_0; \
+ for (r = BUNfirst(b), p = r, q = r + BATcount(b); \
+ p < q; \
+ p++) { \
+ INIT_1; \
+ prb = HASH; \
if (gc) { \
for (hb = hs->hash[prb]; \
hb != BUN_NONE && \
@@ -108,7 +282,7 @@
hb = hs->link[hb]) { \
assert(hs->link[hb] == BUN_NONE \
|| hs->link[hb] < hb); \
- if (w[p] == w[hb]) { \
+ if (COMP) { \
oid grp = ngrps[hb - r]; \
ngrps[p - r] = grp; \
if (histo) \
@@ -121,8 +295,7 @@
} \
if (hb != BUN_NONE && \
grps[hb - r] != grps[p - r]) { \
- /* we didn't assign a group */ \
- /* yet */ \
+ /* no group assigned yet */ \
hb = BUN_NONE; \
} \
} else if (grps) { \
@@ -131,7 +304,7 @@
hb != BUN_NONE; \
hb = hs->link[hb]) { \
if (grps[hb - r] == grps[p - r] && \
- w[p] == w[hb]) { \
+ COMP) { \
oid grp = ngrps[hb - r]; \
ngrps[p - r] = grp; \
if (histo) \
@@ -146,7 +319,7 @@
for (hb = hs->hash[prb]; \
hb != BUN_NONE; \
hb = hs->link[hb]) { \
- if (w[p] == w[hb]) { \
+ if (COMP) { \
oid grp = ngrps[hb - r]; \
ngrps[p - r] = grp; \
if (histo) \
@@ -167,6 +340,23 @@
} \
} while (0)
+#define GRP_create_partial_hash_table_tpe(TYPE) \
+ GRP_create_partial_hash_table( \
+ /* INIT_0 */ TYPE *w = (TYPE *) Tloc(b, 0) , \
+ /* INIT_1 */ , \
+ /* HASH */ hash_##TYPE(hs, &w[p]) , \
+ /* COMP */ w[p] == w[hb] \
+ )
+
+#define GRP_create_partial_hash_table_any() \
+ GRP_create_partial_hash_table( \
+ /* INIT_0 */ , \
+ /* INIT_1 */ v = BUNtail(bi, p) , \
+ /* HASH */ hash_any(hs, v) , \
+ /* COMP */ cmp(v, BUNtail(bi, hb)) == 0 \
+ )
+
+
gdk_return
BATgroup_internal(BAT **groups, BAT **extents, BAT **histo,
BAT *b, BAT *g, BAT *e, BAT *h, int subsorted)
@@ -366,28 +556,36 @@ BATgroup_internal(BAT **groups, BAT **ex
subsorted);
if (grps)
prev = *grps++;
- pv = BUNtail(bi, BUNfirst(b));
ngrps[0] = ngrp;
ngrp++;
if (extents)
exts[0] = b->hseqbase;
if (histo)
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) {
- GRPnotfound();
- } else {
- ngrps[p - r] = ngrp - 1;
- if (histo)
- cnts[ngrp - 1]++;
- }
- pv = v;
- if (grps)
- prev = *grps++;
+
+ switch (ATOMstorage(b->ttype)) {
+ case TYPE_bte:
+ GRP_compare_consecutive_values_tpe(bte);
+ break;
+ case TYPE_sht:
+ GRP_compare_consecutive_values_tpe(sht);
+ break;
+ case TYPE_int:
+ GRP_compare_consecutive_values_tpe(int);
+ break;
+ case TYPE_lng:
+ GRP_compare_consecutive_values_tpe(lng);
+ break;
_______________________________________________
checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list
