Changeset: 9c723d2a480b for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=9c723d2a480b Modified Files: gdk/gdk_analytic.c sql/backends/monet5/sql_rank.c Branch: analytics Log Message:
Eliminated identical branches, plus use BUN for BATcount.
diffs (truncated from 1154 to 300 lines):
diff --git a/gdk/gdk_analytic.c b/gdk/gdk_analytic.c
--- a/gdk/gdk_analytic.c
+++ b/gdk/gdk_analytic.c
@@ -213,49 +213,26 @@ finish:
curval = *bp; \
end = rp + cnt; \
if (p) { \
- if (o) { \
- np = (bit*)Tloc(p, 0); \
- for(; rp<end; np++, rp++, bp++) { \
- if (*np) {
\
- if(is_##TPE##_nil(curval))
\
- has_nils = true;
\
- for (;rb < rp; rb++)
\
- *rb = curval;
\
- curval = *bp;
\
- }
\
- if(!is_##TPE##_nil(*bp)) {
\
- if(is_##TPE##_nil(curval))
\
- curval = *bp;
\
- else
\
- curval = OP(*bp,
curval); \
- }
\
+ np = (bit*)Tloc(p, 0); \
+ for(; rp<end; np++, rp++, bp++) { \
+ if (*np) { \
+ if(is_##TPE##_nil(curval))
\
+ has_nils = true;
\
+ for (;rb < rp; rb++)
\
+ *rb = curval;
\
+ curval = *bp;
\
} \
- if(is_##TPE##_nil(curval)) \
- has_nils = true;
\
- for (;rb < rp; rb++) \
- *rb = curval;
\
- } else { /* single value, ie no ordering */ \
- np = (bit*)Tloc(p, 0); \
- for(; rp<end; np++, rp++, bp++) { \
- if (*np) {
\
- if(is_##TPE##_nil(curval))
\
- has_nils = true;
\
- for (;rb < rp; rb++)
\
- *rb = curval;
\
+ if(!is_##TPE##_nil(*bp)) { \
+ if(is_##TPE##_nil(curval))
\
curval = *bp;
\
- }
\
- if(!is_##TPE##_nil(*bp)) {
\
- if(is_##TPE##_nil(curval))
\
- curval = *bp;
\
- else
\
- curval = OP(*bp,
curval); \
- }
\
+ else
\
+ curval = OP(*bp, curval);
\
} \
- if(is_##TPE##_nil(curval)) \
- has_nils = true;
\
- for (;rb < rp; rb++) \
- *rb = curval;
\
} \
+ if(is_##TPE##_nil(curval)) \
+ has_nils = true; \
+ for (;rb < rp; rb++) \
+ *rb = curval; \
} else if (o) { /* single value, ie no partitions */ \
for(; rp<end; rp++, bp++) { \
if(!is_##TPE##_nil(*bp)) { \
@@ -287,131 +264,103 @@ finish:
#define ANALYTICAL_LIMIT_IMP_HUGE(IMP)
#endif
-#define ANALYTICAL_LIMIT(OP, IMP, SIGN_OP)
\
-gdk_return
\
-GDKanalytical##OP(BAT *r, BAT *b, BAT *p, BAT *o, int tpe)
\
-{
\
- int (*atomcmp)(const void *, const void *);
\
- const void *nil;
\
- bool has_nils = false;
\
- BUN i, j, cnt = BATcount(b);
\
- bit *restrict np;
\
- gdk_return gdk_res = GDK_SUCCEED;
\
-
\
- switch(ATOMstorage(tpe)) {
\
- case TYPE_bit:
\
- ANALYTICAL_LIMIT_IMP(bit, IMP)
\
- break;
\
- case TYPE_bte:
\
- ANALYTICAL_LIMIT_IMP(bte, IMP)
\
- break;
\
- case TYPE_sht:
\
- ANALYTICAL_LIMIT_IMP(sht, IMP)
\
- break;
\
- case TYPE_int:
\
- ANALYTICAL_LIMIT_IMP(int, IMP)
\
- break;
\
- case TYPE_lng:
\
- ANALYTICAL_LIMIT_IMP(lng, IMP)
\
- break;
\
- ANALYTICAL_LIMIT_IMP_HUGE(IMP)
\
- case TYPE_flt:
\
- ANALYTICAL_LIMIT_IMP(flt, IMP)
\
- break;
\
- case TYPE_dbl:
\
- ANALYTICAL_LIMIT_IMP(dbl, IMP)
\
- break;
\
- default: {
\
- BATiter bpi = bat_iterator(b);
\
- void *restrict curval = BUNtail(bpi, 0);
\
- nil = ATOMnilptr(tpe);
\
- atomcmp = ATOMcompare(tpe);
\
- if (p) {
\
- if (o) {
\
- np = (bit*)Tloc(p, 0);
\
- for(i=0,j=0; i<cnt; i++, np++) {
\
- if (*np) {
\
- if((*atomcmp)(curval,
nil) == 0) \
- has_nils =
true; \
- for (;j < i; j++) {
\
- if ((gdk_res =
BUNappend(r, curval, false)) != GDK_SUCCEED) \
- goto
finish; \
- }
\
- curval = BUNtail(bpi,
i); \
- }
\
- void *next = BUNtail(bpi, i);
\
- if((*atomcmp)(next, nil) != 0)
{ \
- if((*atomcmp)(curval,
nil) == 0) \
- curval = next;
\
- else
\
- curval =
atomcmp(next, curval) SIGN_OP 0 ? curval : next; \
- }
\
- }
\
- if((*atomcmp)(curval, nil) == 0)
\
- has_nils = true;
\
- for (;j < i; j++) {
\
- if ((gdk_res = BUNappend(r,
curval, false)) != GDK_SUCCEED) \
- goto finish;
\
- }
\
- } else { /* single value, ie no ordering */
\
- np = (bit*)Tloc(p, 0);
\
- for(i=0,j=0; i<cnt; i++, np++) {
\
- if (*np) {
\
- if((*atomcmp)(curval,
nil) == 0) \
- has_nils =
true; \
- for (;j < i; j++) {
\
- if ((gdk_res =
BUNappend(r, curval, false)) != GDK_SUCCEED) \
- goto
finish; \
- }
\
- curval = BUNtail(bpi,
i); \
- }
\
- void *next = BUNtail(bpi, i);
\
- if((*atomcmp)(next, nil) != 0)
{ \
- if((*atomcmp)(curval,
nil) == 0) \
- curval = next;
\
- else
\
- curval =
atomcmp(next, curval) SIGN_OP 0 ? curval : next; \
- }
\
- }
\
- if((*atomcmp)(curval, nil) == 0)
\
- has_nils = true;
\
- for (;j < i; j++) {
\
- if ((gdk_res = BUNappend(r,
curval, false)) != GDK_SUCCEED) \
- goto finish;
\
- }
\
- }
\
- } else if (o) { /* single value, ie no partitions */
\
- for(i=0; i<cnt; i++) {
\
- void *next = BUNtail(bpi, i);
\
- if((*atomcmp)(next, nil) != 0)
{ \
- if((*atomcmp)(curval,
nil) == 0) \
- curval = next;
\
- else
\
- curval =
atomcmp(next, curval) SIGN_OP 0 ? curval : next; \
- }
\
- }
\
- if((*atomcmp)(curval, nil) == 0)
\
- has_nils = true;
\
- for (j=0; j < i; j++) {
\
- if ((gdk_res = BUNappend(r, curval,
false)) != GDK_SUCCEED) \
- goto finish;
\
- }
\
- } else { /* single value, ie no ordering */
\
- for(i=0; i<cnt; i++) {
\
- void *next = BUNtail(bpi, i);
\
- if((*atomcmp)(next, nil) == 0)
\
- has_nils = true;
\
- if ((gdk_res = BUNappend(r, next,
false)) != GDK_SUCCEED) \
- goto finish;
\
- }
\
- }
\
- }
\
- }
\
-finish:
\
- BATsetcount(r, cnt);
\
- r->tnonil = !has_nils;
\
- r->tnil = has_nils;
\
- return gdk_res;
\
+#define ANALYTICAL_LIMIT(OP, IMP, SIGN_OP)
\
+gdk_return
\
+GDKanalytical##OP(BAT *r, BAT *b, BAT *p, BAT *o, int tpe)
\
+{
\
+ int (*atomcmp)(const void *, const void *);
\
+ const void *nil;
\
+ bool has_nils = false;
\
+ BUN i, j, cnt = BATcount(b);
\
+ bit *restrict np;
\
+ gdk_return gdk_res = GDK_SUCCEED;
\
+
\
+ switch(ATOMstorage(tpe)) {
\
+ case TYPE_bit:
\
+ ANALYTICAL_LIMIT_IMP(bit, IMP)
\
+ break;
\
+ case TYPE_bte:
\
+ ANALYTICAL_LIMIT_IMP(bte, IMP)
\
+ break;
\
+ case TYPE_sht:
\
+ ANALYTICAL_LIMIT_IMP(sht, IMP)
\
+ break;
\
+ case TYPE_int:
\
+ ANALYTICAL_LIMIT_IMP(int, IMP)
\
+ break;
\
+ case TYPE_lng:
\
+ ANALYTICAL_LIMIT_IMP(lng, IMP)
\
+ break;
\
+ ANALYTICAL_LIMIT_IMP_HUGE(IMP)
\
+ case TYPE_flt:
\
+ ANALYTICAL_LIMIT_IMP(flt, IMP)
\
+ break;
\
+ case TYPE_dbl:
\
+ ANALYTICAL_LIMIT_IMP(dbl, IMP)
\
+ break;
\
+ default: {
\
+ BATiter bpi = bat_iterator(b);
\
+ void *restrict curval = BUNtail(bpi, 0);
\
+ nil = ATOMnilptr(tpe);
\
+ atomcmp = ATOMcompare(tpe);
\
+ if (p) {
\
+ np = (bit*)Tloc(p, 0);
\
+ for(i=0,j=0; i<cnt; i++, np++) {
\
+ if (*np) {
\
+ if((*atomcmp)(curval, nil) ==
0) \
+ has_nils = true;
\
+ for (;j < i; j++) {
\
+ if ((gdk_res =
BUNappend(r, curval, false)) != GDK_SUCCEED) \
+ goto finish;
\
+ }
\
+ curval = BUNtail(bpi, i);
\
+ }
\
+ void *next = BUNtail(bpi, i);
\
+ if((*atomcmp)(next, nil) != 0) {
\
+ if((*atomcmp)(curval, nil) ==
0) \
+ curval = next;
\
+ else
\
+ curval = atomcmp(next,
curval) SIGN_OP 0 ? curval : next; \
+ }
\
+ }
\
+ if((*atomcmp)(curval, nil) == 0)
\
+ has_nils = true;
\
+ for (;j < i; j++) {
\
+ if ((gdk_res = BUNappend(r, curval,
false)) != GDK_SUCCEED) \
+ goto finish;
\
+ }
\
+ } else if (o) { /* single value, ie no partitions */
\
+ for(i=0; i<cnt; i++) {
\
+ void *next = BUNtail(bpi, i);
\
+ if((*atomcmp)(next, nil) != 0)
{ \
+ if((*atomcmp)(curval,
nil) == 0) \
+ curval = next;
\
+ else
\
+ curval =
atomcmp(next, curval) SIGN_OP 0 ? curval : next; \
+ }
\
+ }
\
+ if((*atomcmp)(curval, nil) == 0)
\
+ has_nils = true;
\
+ for (j=0; j < i; j++) {
\
+ if ((gdk_res = BUNappend(r, curval,
false)) != GDK_SUCCEED) \
+ goto finish;
\
+ }
\
+ } else { /* single value, ie no ordering */
\
+ for(i=0; i<cnt; i++) {
\
+ void *next = BUNtail(bpi, i);
\
+ if((*atomcmp)(next, nil) == 0)
\
+ has_nils = true;
\
+ if ((gdk_res = BUNappend(r, next,
false)) != GDK_SUCCEED) \
+ goto finish;
\
+ }
\
+ }
\
+ }
\
+ }
\
+finish:
\
+ BATsetcount(r, cnt);
\
+ r->tnonil = !has_nils;
\
+ r->tnil = has_nils;
\
+ return gdk_res;
\
}
ANALYTICAL_LIMIT(min, MIN, >)
@@ -613,181 +562,124 @@ GDKanalyticalcount(BAT *r, BAT *b, BAT *
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list
