Changeset: a78619d7d649 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=a78619d7d649
Modified Files:
gdk/gdk_group.c
gdk/gdk_select.c
Branch: default
Log Message:
mergine
diffs (truncated from 607 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,37 @@
* At the MAL level, the multigroup function would perform the dynamic
* optimization.
*/
+#define GRPhashloop(TYPE) \
+ do { \
+ v = BUNtail(bi, p); \
+ if (grps) { \
+ prb = hash_##TYPE(hs, v) ^ hash_oid(hs, &grps[p-r]); \
+ for (hb = hs->hash[prb]; \
+ hb != BUN_NONE; \
+ hb = hs->link[hb]) { \
+ if (grps[hb - r] == grps[p - r] && \
+ *(TYPE *) v == *(TYPE *) BUNtail(bi, hb)){ \
+ ngrps[p - r] = ngrps[hb - r]; \
+ if (histo) \
+ cnts[ngrps[hb - r]]++; \
+ break; \
+ } \
+ } \
+ } else { \
+ prb = hash_##TYPE(hs, v); \
+ for (hb = hs->hash[prb]; \
+ hb != BUN_NONE; \
+ hb = hs->link[hb]) { \
+ if (*(TYPE *) v == *(TYPE *) BUNtail(bi, hb)){ \
+ ngrps[p - r] = ngrps[hb - r]; \
+ if (histo) \
+ cnts[ngrps[hb - r]]++; \
+ break; \
+ } \
+ } \
+ } \
+ } while (0)
+
gdk_return
BATgroup_internal(BAT **groups, BAT **extents, BAT **histo,
BAT *b, BAT *g, BAT *e, BAT *h, int subsorted)
@@ -111,7 +142,8 @@ BATgroup_internal(BAT **groups, BAT **ex
if (b->tkey || BATcount(b) <= 1 || (g && (g->tkey || BATtdense(g)))) {
/* grouping is trivial: 1 element per group */
- ALGODEBUG fprintf(stderr, "#BATgroup: trivial case: 1 element
per group\n");
+ ALGODEBUG fprintf(stderr, "#BATgroup: trivial case: "
+ "1 element per group\n");
if (BATcount(b) == 1 && b->htype == TYPE_oid)
ngrp = * (oid *) Hloc(b, BUNfirst(b));
else
@@ -146,7 +178,8 @@ BATgroup_internal(BAT **groups, BAT **ex
/* all values are equal */
if (g == NULL) {
/* there's only a single group: 0 */
- ALGODEBUG fprintf(stderr, "#BATgroup: trivial case:
single output group\n");
+ ALGODEBUG fprintf(stderr, "#BATgroup: trivial case: "
+ "single output group\n");
ngrp = 0;
gn = BATconstant(TYPE_oid, &ngrp, BATcount(b));
if (gn == NULL)
@@ -178,7 +211,8 @@ BATgroup_internal(BAT **groups, BAT **ex
* e/h available in order to copy them,
* otherwise we will need to calculate them
* which we will do using the "normal" case */
- ALGODEBUG fprintf(stderr, "#BATgroup: trivial case:
copy input groups\n");
+ ALGODEBUG fprintf(stderr, "#BATgroup: trivial case: "
+ "copy input groups\n");
gn = BATcopy(g, g->htype, g->ttype, 0);
if (gn == NULL)
goto error;
@@ -249,7 +283,9 @@ BATgroup_internal(BAT **groups, BAT **ex
if ((grps && *grps != prev) || cmp(pv, v) != 0) {
ngrp++;
if (ngrp == maxgrps) {
- /* we need to extend extents and histo
bats, do it once */
+ /* we need to extend extents
+ * and histo bats, do it
+ * once */
maxgrps = BATcount(b);
if (extents) {
BATsetcount(en, ngrp);
@@ -324,7 +360,8 @@ BATgroup_internal(BAT **groups, BAT **ex
}
/* start a new group */
if (ngrp == maxgrps) {
- /* we need to extend extents and histo bats, do
it once */
+ /* we need to extend extents and histo
+ * bats, do it once */
maxgrps = BATcount(b);
if (extents) {
BATsetcount(en, ngrp);
@@ -371,7 +408,9 @@ BATgroup_internal(BAT **groups, BAT **ex
if (hb == BUN_NONE) {
/* no equal found: start new group */
if (ngrp == maxgrps) {
- /* we need to extend extents and histo
bats, do it once */
+ /* we need to extend extents
+ * and histo bats, do it
+ * once */
maxgrps = BATcount(b);
if (extents) {
BATsetcount(en, ngrp);
@@ -425,53 +464,50 @@ BATgroup_internal(BAT **groups, BAT **ex
GDKerror("BATgroup: cannot allocate hash table\n");
goto error;
}
-#define GRPhashloop(TYPE,EXP1,EXP2) {\
-v = BUNtail(bi, p);\
-prb = hash_##TYPE(hs, v) EXP1;\
-for (hb = hs->hash[prb];\
- hb != BUN_NONE;\
- hb = hs->link[hb]) {\
- if (EXP2 *(TYPE*) v == *(TYPE*) BUNtail(bi,hb) ){\
- ngrps[p - r] = ngrps[hb - r];\
- if (histo)\
- cnts[ngrps[hb - r]]++;\
- break;\
- }\
-} }
-
-#define GRPhashfactor(TYPE) \
- if (grps == NULL ) { GRPhashloop(TYPE,, ) }\
- else GRPhashloop(TYPE, ^ hash_oid(hs, (oid *)&grps[p-r]) ,grps[hb - r]
== grps[p - r] &&)
-
-#define GRPhashswitch \
-switch( ATOMstorage(hs->type)){\
-case TYPE_bte: GRPhashfactor(bte); break;\
-case TYPE_sht: GRPhashfactor(sht); break;\
-case TYPE_int: GRPhashfactor(int); break;\
-case TYPE_flt: GRPhashfactor(flt); break;\
-case TYPE_lng: GRPhashfactor(lng); break;\
-default: \
- v = BUNtail(bi, p);\
- prb = hash_any(hs, v);\
- for (hb = hs->hash[prb];\
- hb != BUN_NONE;\
- hb = hs->link[hb]) {\
- if ((grps == NULL ||\
- grps[hb - r] == grps[p - r]) &&\
- cmp(v, BUNtail(bi, hb)) == 0) {\
- ngrps[p - r] = ngrps[hb - r];\
- if (histo)\
- cnts[ngrps[hb - r]]++;\
- break;\
- } } }
for (r = BUNfirst(b), p = r, q = r + BATcount(b); p < q; p++) {
- GRPhashswitch;
+ switch (ATOMstorage(hs->type)) {
+ case TYPE_bte:
+ GRPhashloop(bte);
+ break;
+ case TYPE_sht:
+ GRPhashloop(sht);
+ break;
+ case TYPE_int:
+ GRPhashloop(int);
+ break;
+ case TYPE_lng:
+ GRPhashloop(lng);
+ break;
+ case TYPE_flt:
+ GRPhashloop(flt);
+ break;
+ case TYPE_dbl:
+ GRPhashloop(dbl);
+ break;
+ default:
+ v = BUNtail(bi, p);
+ prb = hash_any(hs, v);
+ for (hb = hs->hash[prb];
+ hb != BUN_NONE;
+ hb = hs->link[hb]) {
+ if ((grps == NULL ||
+ grps[hb - r] == grps[p - r]) &&
+ cmp(v, BUNtail(bi, hb)) == 0) {
+ ngrps[p - r] = ngrps[hb - r];
+ if (histo)
+ cnts[ngrps[hb - r]]++;
+ break;
+ }
+ }
+ }
if (hb == BUN_NONE) {
/* no equal found: start new group and
* enter into hash table */
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);
diff --git a/gdk/gdk_select.c b/gdk/gdk_select.c
--- a/gdk/gdk_select.c
+++ b/gdk/gdk_select.c
@@ -179,110 +179,157 @@ BAT_hashselect(BAT *b, BAT *s, BAT *bn,
} \
} while (0)
-#define addresult(I) {\
- if( cnt == lim ){ \
- BATextend(bn, BATcount( b));\
- lim = BATcapacity(bn); \
- dst = (oid*) Tloc(bn, bn->U->first);\
- } \
- (dst)[cnt++] = I;\
-}
+#define LT(a, b) ((a) < (b))
+#define LE(a, b) ((a) <= (b))
+#define GT(a, b) ((a) > (b))
+#define GE(a, b) ((a) >= (b))
-#define SCANLOOPCAND5(TYPE,OP1,OP2,OP3,OP4)\
- do { TYPE *src = (TYPE*) Tloc(b, b->U->first);\
- oid *dst = (oid*) Tloc(bn, bn->U->first);\
- BUN lim = BATcapacity(bn); \
- BUN r;\
- if (equi){\
- assert(li && hi);\
- assert(!anti);\
- for ((i) = (p); (i) < (q); (i)++){ \
- r = (BUN) (*candlist++ - off) ;\
- if ( (src)[r] == *(TYPE*) tl ) \
- addresult(r);\
- }\
- } else if (anti){\
- if ( nil == NULL) \
- for ((i) = (p); (i) < (q); (i)++) {\
- r = (BUN) (*candlist++ - off) ;\
- if ( ((lval && ( *(TYPE*) tl OP1 (src)[r])) )
||\
- (hval && ( *(TYPE*) th OP2 (src)[r])) )\
- addresult(r);\
- } else \
- for ((i) = (p); (i) < (q); (i)++) {\
- r = (BUN) (*candlist++ - off) ;\
- if ( ((lval && ( *(TYPE*) tl OP1 (src)[r]) ) ||\
- (hval && ( *(TYPE*) th OP2 (src)[r]) )))\
- if ( (src)[r] != TYPE##_nil)
addresult(r); \
- }\
- } else {\
- if ( nil == NULL) \
- for ((i) = (p); (i) < (q); (i)++) {\
- r = (BUN) (*candlist++ - off) ;\
- if ( (!lval || ( *(TYPE*) tl OP3 (src)[r] )) &&
\
- (!hval || ( *(TYPE*) th OP4 (src)[r] )) ) \
- addresult(r);\
- } else \
- for ((i) = (p); (i) < (q); (i)++) {\
- r = (BUN) (*candlist++ - off) ;\
- if ( (!lval || ( *(TYPE*) tl OP3 (src)[r] )) &&
\
- (!hval || ( *(TYPE*) th OP4 (src)[r] )) ) \
- if ( (src)[r] != TYPE##_nil)
addresult(r); \
- }\
- }\
- BATsetcount(bn,cnt);\
- } while (0);
+#define addresult(I) \
+ do { \
+ if (cnt == lim) { \
+ BATextend(bn, BATcount(b)); \
+ lim = BATcapacity(bn); \
+ dst = (oid*) Tloc(bn, bn->U->first); \
+ } \
+ dst[cnt++] = I; \
+ } while (0)
-#define SCANLOOPCAND(TYPE) \
- if ( li && hi ) { SCANLOOPCAND5(TYPE,>,<,<=,>=) } \
- else if (li ) {SCANLOOPCAND5(TYPE,>,<=,<=,>) } \
- else if (hi ) {SCANLOOPCAND5(TYPE,>=,<,<,>=) } \
- else {SCANLOOPCAND5(TYPE,>=,<=,<,>) }
+#define SCANLOOPCAND5(TYPE, OP1, OP2) \
+ do { \
+ TYPE *src = (TYPE *) Tloc(b, b->U->first); \
+ oid *dst = (oid *) Tloc(bn, bn->U->first); \
+ BUN lim = BATcapacity(bn); \
+ BUN r; \
+ if (equi) { \
+ assert(li && hi); \
+ assert(!anti); \
+ for (i = p; i < q; i++) { \
+ r = (BUN) (*candlist++ - off); \
+ if (src[r] == *(TYPE *) tl) \
+ addresult(r); \
+ } \
+ } else if (anti) { \
+ if (nil == NULL) { \
+ for (i = p; i < q; i++) { \
+ r = (BUN) (*candlist++ - off) ; \
+ if ((lval && \
+ OP1(*(TYPE *) tl, src[r])) || \
+ (hval && \
+ OP2(*(TYPE *) th, src[r]))) \
+ addresult(r); \
+ } \
+ } else { \
+ for (i = p; i < q; i++) { \
_______________________________________________
checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list