Changeset: c0d04f616d87 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=c0d04f616d87
Modified Files:
monetdb5/modules/kernel/algebra.mx
Branch: default
Log Message:
Converted a whole bunch of Mx macro uses to functions using function pointers.
In the process, elimiated a whole bunch of CMD* intermediate (M4-era)
functions.
diffs (truncated from 603 to 300 lines):
diff --git a/monetdb5/modules/kernel/algebra.mx
b/monetdb5/modules/kernel/algebra.mx
--- a/monetdb5/modules/kernel/algebra.mx
+++ b/monetdb5/modules/kernel/algebra.mx
@@ -1486,72 +1486,6 @@ CMDbandjoin(BAT **result, BAT *left, BAT
return (*result = BATbandjoin(left, right, minus, plus, *li, *hi)) ?
GDK_SUCCEED : GDK_FAIL;
}
-/*
- * @-
- * Let's cut this text down with some Mx macros
- */
-@= unary
-static int
-CMD@1(BAT **result, BAT *b)
-{
- return (*result = @2(b))?GDK_SUCCEED:GDK_FAIL;
-}
-@= binary
-static int
-CMD@1(BAT **result, BAT *left, BAT* right)
-{
- return (*result = @2(left, right))?GDK_SUCCEED:GDK_FAIL;
-}
-@= binaryestimate
-static int
-CMD@1(BAT **result, BAT *left, BAT* right, lng *estimate)
-{
- return (*result = @2(left, right, *estimate == lng_nil || *estimate < 0
? BUN_NONE : (*estimate >= (lng) BUN_MAX ? BUN_MAX : (BUN) *estimate))) ?
GDK_SUCCEED : GDK_FAIL;
-}
-@= binaryint
-static int
-CMD@1(BAT **result, BAT* b, int *param)
-{
- return (*result = @2(b, *param))?GDK_SUCCEED:GDK_FAIL;
-}
-@
-@h
-#define BATtdiff(l,r) BATmirror(BATkdiff(BATmirror(l),BATmirror(r)))
-#define BATtintersect(l,r) BATmirror(BATkintersect(BATmirror(l),BATmirror(r)))
-#define BATtsort(b) BATmirror(BATsort(BATmirror(b)))
-#define BATtsort_rev(b) BATmirror(BATsort_rev(BATmirror(b)))
-#define BAThistogram_rev(b) BAThistogram(BATmirror(b))
-#define BATmark_default(b) BATmark(b,OIDnew(BATcount(b)))
-#define BATtmark_default(b)
BATmirror(BATmark(BATmirror(b),OIDnew(BATcount(b))))
-#define BAThmark_default(b) BATmirror(BATmark(b,OIDnew(BATcount(b))))
-#define BATwcopy(b) BATcopy(b, b->htype, b->ttype, 1)
-@c
-@:unary(histogram,BAThistogram)@
-@:unary(sort,BATsort)@
-@:unary(sort_rev,BATsort_rev)@
-@:unary(tsort,BATtsort)@
-@:unary(ssort,BATssort)@
-@:unary(ssort_rev,BATssort_rev)@
-@:unary(number,BATnumber)@
-@:unary(copy,BATwcopy)@
-@:unary(kunique,BATkunique)@
-@:unary(sunique,BATsunique)@
-@:binary(semijoin,BATsemijoin)@
-@:binary(cross,BATcross)@
-@:binary(antijoin,BATantijoin)@
-@:binaryestimate(join,BATjoin)@
-@:binaryestimate(fetchjoin,BATfetchjoin)@
-@:binaryestimate(leftjoin,BATleftjoin)@
-@:binaryestimate(leftfetchjoin,BATleftfetchjoin)@
-@:binaryestimate(outerjoin,BATouterjoin)@
-@:binary(sunion,BATsunion)@
-@:binary(kunion,BATkunion)@
-@:binary(sintersect,BATsintersect)@
-@:binary(kintersect,BATkintersect)@
-@:binary(sdiff,BATsdiff)@
-@:binary(kdiff,BATkdiff)@
-@:binaryint(sample,BATsample)@
-
static int
CMDgen_group(BAT **result, BAT *b )
{
@@ -1858,11 +1792,11 @@ CMDexistBUN(bit *ret, BAT *b, ptr val, p
return GDK_SUCCEED;
}
-static int
-CMDmerge(BAT **ret, BAT *b)
+static BAT *
+BATmerge(BAT *b)
{
BUN n = BATcount(b);
- BAT *bn = *ret = BATnew(TYPE_lng, TYPE_void, n);
+ BAT *bn = BATnew(TYPE_lng, TYPE_void, n);
BATiter bni = bat_iterator(bn), bi = bat_iterator(b);
BUN p, q;
lng *r = (lng *) BUNhead(bni, BUNfirst(bn));
@@ -1887,15 +1821,15 @@ CMDmerge(BAT **ret, BAT *b)
BATkey(bn, BAThkey(b) || BATtkey(b)) ;
BATkey(BATmirror(bn), FALSE) ;
- return GDK_SUCCEED;
+ return bn;
}
-static int
-CMDsplit(BAT **ret, BAT *b)
+static BAT *
+BATsplit(BAT *b)
{
BATiter bi = bat_iterator(b);
BUN n = BATcount(b);
- BAT *bn = *ret = BATnew(TYPE_oid, TYPE_oid, n);
+ BAT *bn = BATnew(TYPE_oid, TYPE_oid, n);
BUN i;
lng *r = (lng *) BUNhead(bi, BUNfirst(b));
@@ -1919,11 +1853,11 @@ CMDsplit(BAT **ret, BAT *b)
BATkey(bn, FALSE) ;
BATkey(BATmirror(bn), FALSE) ;
- return GDK_SUCCEED;
+ return bn;
bunins_failed:
BATaccessEnd(b,USE_HEAD,MMAP_SEQUENTIAL);
BBPreclaim(bn);
- return GDK_FAIL;
+ return NULL;
}
/*
@@ -2650,145 +2584,261 @@ ALGrangejoin(int *result, int *lid, int
throw(MAL, "algebra.rangejoin", GDK_EXCEPTION);
}
-/*
- * @-
- * Let cut this text down with some Mx macro's
- */
-@= ALGunary
-str ALG@1(int *result, int *bid) {
+static str
+ALGunary(int *result, int *bid, BAT *(*func)(BAT *), const char *name)
+{
BAT *b,*bn;
- if( (b= BATdescriptor(*bid)) == NULL ){
- throw(MAL, "algebra.@1", RUNTIME_OBJECT_MISSING);
+
+ if ((b= BATdescriptor(*bid)) == NULL) {
+ throw(MAL, name, RUNTIME_OBJECT_MISSING);
}
- CMD@1(&bn,b);
- if( bn ) {
- if (!(bn->batDirty&2)) bn = BATsetaccess(bn, BAT_READ);
- *result = bn->batCacheid;
- BBPkeepref(*result);
- BBPreleaseref(b->batCacheid);
- return MAL_SUCCEED;
- }
+ bn = (*func)(b);
BBPreleaseref(b->batCacheid);
- throw(MAL, "algebra.@1", GDK_EXCEPTION);
-}
-@= ALGunaryint
-str ALG@1(int *result, int *bid) {
- BAT *b,*bn= NULL;
- if( (b= BATdescriptor(*bid)) == NULL ){
- throw(MAL, "algebra.@1", RUNTIME_OBJECT_MISSING);
- }
- CMD@1(&bn,b);
- if( bn ) {
- if (!(bn->batDirty&2)) bn = BATsetaccess(bn, BAT_READ);
- *result = bn->batCacheid;
- BBPkeepref(*result);
- BBPreleaseref(b->batCacheid);
- return MAL_SUCCEED;
- }
- BBPreleaseref(b->batCacheid);
+ if (bn == NULL)
+ throw(MAL, "algebra.@1", GDK_EXCEPTION);
+ if (!(bn->batDirty&2))
+ bn = BATsetaccess(bn, BAT_READ);
+ *result = bn->batCacheid;
+ BBPkeepref(*result);
return MAL_SUCCEED;
}
-@= ALGbinary
-str ALG@1(int *result, int *lid, int *rid) {
+
+static str
+ALGbinary(int *result, int *lid, int *rid, BAT *(*func)(BAT *, BAT *), const
char *name)
+{
BAT *left, *right,*bn= NULL;
- if( (left= BATdescriptor(*lid)) == NULL ){
- throw(MAL, "algebra.@1", RUNTIME_OBJECT_MISSING);
+
+ if ((left = BATdescriptor(*lid)) == NULL) {
+ throw(MAL, name, RUNTIME_OBJECT_MISSING);
}
- if( (right= BATdescriptor(*rid)) == NULL ){
+ if ((right = BATdescriptor(*rid)) == NULL) {
BBPreleaseref(left->batCacheid);
- throw(MAL, "algebra.@1", RUNTIME_OBJECT_MISSING);
+ throw(MAL, name, RUNTIME_OBJECT_MISSING);
}
- if( CMD@1(&bn,left, right) == GDK_FAIL){
- BBPreleaseref(left->batCacheid);
- BBPreleaseref(right->batCacheid);
- if( bn) BBPunfix(bn->batCacheid);
- throw(MAL, "algebra.@1", GDK_EXCEPTION);
- }
- if( bn ) {
- if (!(bn->batDirty&2)) bn = BATsetaccess(bn, BAT_READ);
- *result = bn->batCacheid;
- BBPkeepref(*result);
- BBPreleaseref(left->batCacheid);
- BBPreleaseref(right->batCacheid);
- return MAL_SUCCEED;
- }
+ bn = (*func)(left, right);
BBPreleaseref(left->batCacheid);
BBPreleaseref(right->batCacheid);
- throw(MAL, "algebra.@1", GDK_EXCEPTION);
+ if (bn == NULL)
+ throw(MAL, name, GDK_EXCEPTION);
+ if (!(bn->batDirty&2))
+ bn = BATsetaccess(bn, BAT_READ);
+ *result = bn->batCacheid;
+ BBPkeepref(*result);
+ return MAL_SUCCEED;
}
-@= ALGbinaryint
-str ALG@1(int *result, int* bid, int *param) {
- BAT *b, *bn= NULL;
- if( (b= BATdescriptor(*bid)) == NULL ){
- throw(MAL, "algebra.@1", RUNTIME_OBJECT_MISSING);
+
+static str
+ALGbinaryint(bat *result, bat *bid, int *param, BAT *(*func)(BAT *, BUN),
const char *name)
+{
+ BAT *b, *bn = NULL;
+
+ if ((b = BATdescriptor(*bid)) == NULL) {
+ throw(MAL, name, RUNTIME_OBJECT_MISSING);
}
- CMD@1(&bn,b, param);
- if( bn ) {
- if (!(bn->batDirty&2)) bn = BATsetaccess(bn, BAT_READ);
- *result = bn->batCacheid;
- BBPkeepref(*result);
- BBPreleaseref(b->batCacheid);
- return MAL_SUCCEED;
+ bn = (*func)(b, *param);
+ BBPreleaseref(b->batCacheid);
+ if (bn == NULL)
+ throw(MAL, name, GDK_EXCEPTION);
+ if (!(bn->batDirty & 2))
+ bn = BATsetaccess(bn, BAT_READ);
+ *result = bn->batCacheid;
+ BBPkeepref(*result);
+ return MAL_SUCCEED;
+}
+
+static str
+ALGbinaryestimate(int *result, int *lid, int *rid, lng *estimate,
+ BAT *(*func)(BAT *, BAT *, BUN), const char
*name)
+{
+ BAT *left, *right, *bn = NULL;
+
+ if ((left = BATdescriptor(*lid)) == NULL) {
+ throw(MAL, name, RUNTIME_OBJECT_MISSING);
}
- BBPreleaseref(b->batCacheid);
- throw(MAL, "algebra.@1", GDK_EXCEPTION);
-}
-@= ALGbinaryestimate
-str ALG@1estimate(int *result, int *lid, int *rid, lng *estimate) {
- BAT *left, *right,*bn=NULL;
- if( (left= BATdescriptor(*lid)) == NULL ){
- throw(MAL, "algebra.@1", RUNTIME_OBJECT_MISSING);
+ if ((right = BATdescriptor(*rid)) == NULL) {
+ BBPreleaseref(left->batCacheid);
+ throw(MAL, name, RUNTIME_OBJECT_MISSING);
}
- if( (right= BATdescriptor(*rid)) == NULL ){
- BBPreleaseref(left->batCacheid);
- throw(MAL, "algebra.@1", RUNTIME_OBJECT_MISSING);
- }
- if( CMD@1(&bn,left, right, estimate) == GDK_FAIL){
- BBPreleaseref(left->batCacheid);
- BBPreleaseref(right->batCacheid);
- if( bn) BBPunfix(bn->batCacheid);
- throw(MAL, "algebra.@1", GDK_EXCEPTION);
- }
- if( bn ) {
- if (!(bn->batDirty&2)) bn = BATsetaccess(bn, BAT_READ);
- *result = bn->batCacheid;
- BBPkeepref(*result);
- BBPreleaseref(left->batCacheid);
- BBPreleaseref(right->batCacheid);
- return MAL_SUCCEED;
- }
+ bn = (*func)(left, right, estimate ? (BUN) *estimate : BUN_NONE);
BBPreleaseref(left->batCacheid);
BBPreleaseref(right->batCacheid);
- throw(MAL, "algebra.@1", GDK_EXCEPTION);
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list