Update of /cvsroot/monetdb/MonetDB5/src/modules/kernel
In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv28347/src/modules/kernel

Modified Files:
        batcalc.mx batifthen.mx group.mx kprelude.mx 
Log Message:
batifthen.mx: use (fast) direct assignments instead of bunfastins for 
ifthenelse (not for ifthen as it can be small as the input bat)
group.mx: return read only bats.

(rest small ident and whitespace fixes)


Index: kprelude.mx
===================================================================
RCS file: /cvsroot/monetdb/MonetDB5/src/modules/kernel/kprelude.mx,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- kprelude.mx 4 Oct 2007 10:37:26 -0000       1.7
+++ kprelude.mx 11 Dec 2007 17:32:02 -0000      1.8
@@ -25,18 +25,30 @@
 if( bn== NULL) {*ret= 0;
     throw(MAL, @1, "can not create bat");}
 
[EMAIL PROTECTED] resBAT
+    bn = BATnew(ATOMtype(b->htype), [EMAIL PROTECTED], BATcount(b));
+    if ( bn== NULL) {
+       @3
+       throw(MAL, @2, "can not create bat");
+    }
+    bn->hsorted = b->hsorted;
+    bn->tsorted = b->tsorted;
+    BATkey(bn, BAThkey(b));
+
 @= resultBAT
     if (BAThvoid(b)) {
         bn = BATnew(TYPE_void, [EMAIL PROTECTED], BATcount(b));
         BATseqbase(bn, b->hseqbase);
-    } else 
+    } else {
         bn = BATnew(b->htype, [EMAIL PROTECTED], BATcount(b));
-       if( bn== NULL) {
-               @3
-               throw(MAL, @2, "can not create bat");
-       }
+    }
+    if ( bn== NULL) {
+       @3
+       throw(MAL, @2, "can not create bat");
+    }
     bn->hsorted = b->hsorted;
     bn->tsorted = b->tsorted;
+    BATkey(bn, BAThkey(b));
 
 @= voidresultBAT
        bn = BATnew(TYPE_void, @1, BATcount(b));

Index: batcalc.mx
===================================================================
RCS file: /cvsroot/monetdb/MonetDB5/src/modules/kernel/batcalc.mx,v
retrieving revision 1.145
retrieving revision 1.146
diff -u -d -r1.145 -r1.146
--- batcalc.mx  9 Dec 2007 16:10:09 -0000       1.145
+++ batcalc.mx  11 Dec 2007 17:32:02 -0000      1.146
@@ -50,6 +50,7 @@
 for NULLs in each and every basic operation +,-,/,* and comparisons.
 This variant can be obtained using a compile time flag (NULLTST) for the time
 being. If it turns out to be effective, we will derive a new
+
 version of batcalc.
 Experiments show that ignoring the NULLS saves about 15\%
 for larger instructions.

Index: batifthen.mx
===================================================================
RCS file: /cvsroot/monetdb/MonetDB5/src/modules/kernel/batifthen.mx,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- batifthen.mx        14 Nov 2007 12:52:15 -0000      1.10
+++ batifthen.mx        11 Dec 2007 17:32:02 -0000      1.11
@@ -50,13 +50,14 @@
 @mal
        @:ifthenGrp(bit)@
        @:ifthenGrp(chr)@
-       @:ifthenGrp(str)@
-       @:ifthenGrp(oid)@
-       @:ifthenGrp(int)@
+       @:ifthenGrp(bte)@
        @:ifthenGrp(sht)@
+       @:ifthenGrp(int)@
        @:ifthenGrp(lng)@
+       @:ifthenGrp(oid)@
        @:ifthenGrp(flt)@
        @:ifthenGrp(dbl)@
+       @:ifthenGrp(str)@
 @- Implementation
 @include kprelude.mx
 @h
@@ -89,21 +90,18 @@
     BBPkeepref(*ret);
     BBPreleaseref(b->batCacheid);
     return MAL_SUCCEED;
[EMAIL PROTECTED] resBAT
-       if (BAThvoid(b)) {
-               bn = BATnew(TYPE_oid, [EMAIL PROTECTED], BATcount(b));
-               BATseqbase(bn, b->hseqbase);
-       } else {
-               bn = BATnew(b->htype, [EMAIL PROTECTED], BATcount(b));
-       }
-       if( bn== NULL) {
-               @3
-               throw(MAL, @2, "can not create bat");
+
[EMAIL PROTECTED] void_wrapup
+       if (!(bn->batDirty&2)) bn = BATsetaccess(bn, BAT_READ);
+       if (b->htype != bn->htype) {
+               BAT *r = VIEWcreate(b,bn);
+
+               BBPreleaseref(bn->batCacheid);
+               bn = r;
        }
-       bn->hsorted = b->hsorted;
-       bn->tsorted = FALSE;
-       BATkey(bn, BAThkey(b));
-       BATkey(BATmirror(bn), FALSE);
+       BBPkeepref(*ret = bn->batCacheid);
+       BBPreleaseref(b->batCacheid);
+       return MAL_SUCCEED;
 
 @- IfThenElse
 The conditional multiplex operations .
@@ -112,7 +110,7 @@
 String arguments call for an extra type casting. In combination
 with type resolution and runtime checks it provides a dense
 definitoin.
[EMAIL PROTECTED] ifthencstImpl
[EMAIL PROTECTED] ifthenImpl
 batifthen_export str [EMAIL PROTECTED](int *ret, int *bid, int *tid);
 str
 [EMAIL PROTECTED](int *ret, int *bid, int *tid) 
@@ -126,16 +124,10 @@
        @:getBATdescriptor(bid,b,"batcalc.ifThen")@
        
@:getBATdescriptor(tid,tb,"batcalc.ifThen",BBPreleaseref(b->batCacheid))@
        @:chkSize(b,tb,CMDifThen)@
-
-       bn= BATnew(ATOMtype(b->htype),[EMAIL PROTECTED],BATcount(b));
-       if( bn == 0 )
-               throw(MAL, "batcalc.ifThen","Can not create BAT");
-       bn->hsorted= b->hsorted;
-       bn->tsorted= b->tsorted;
+       @:resBAT(@1,"batcalc.ifThen")@
 
        bi = bat_iterator(b);
        tbi = bat_iterator(tb);
-
        t = (bit*)Tloc(b,BUNfirst(b));
 
        BATloop(b, p, q) {
@@ -162,8 +154,6 @@
 
        @:getBATdescriptor(bid,b,"batcalc.ifThen")@
        @:resBAT(@1,"batcalc.ifThen")@
-       bn->hsorted= b->hsorted;
-       bn->tsorted= b->tsorted;
 
        bi = bat_iterator(b);
        t = (bit*)Tloc(b,BUNfirst(b));
@@ -177,6 +167,157 @@
        }
        @:wrapup@
 }
+
[EMAIL PROTECTED] ifthenelseImpl
+batifthen_export str [EMAIL PROTECTED](int *ret, int *bid, @1 *tid, @1 *eid);
+str [EMAIL PROTECTED](int *ret, int *bid, @1 *tid, @1 *eid)
+{
+       BAT *b, *bn;
+       @1 nilval= (@1) @1_nil, *dst;
+       bit *t;
+       size_t cnt, p;
+
+       @:getBATdescriptor(bid,b,"batcalc.ifThenElse")@
+       @:voidresultBAT([EMAIL PROTECTED],"batcalc.ifThenElse")@
+       bn->tsorted = FALSE;
+       BATkey(BATmirror(bn), FALSE);
+
+       cnt = BATcount(b);
+       t = (bit*)Tloc(b,BUNfirst(b));
+       dst = (@1*)Tloc(bn, BUNfirst(bn));
+
+       for (p=0; p<cnt; p++) {
+               if (t[p] == bit_nil) 
+                       dst[p] = nilval;
+               else if (t[p]) 
+                       dst[p] = *tid;
+               else
+                       dst[p] = *eid;
+       }
+       BATsetcount(bn, p);
+       @:void_wrapup@
+}
+
+batifthen_export str [EMAIL PROTECTED](int *ret, int *bid, int *tid, int *eid);
+str
[EMAIL PROTECTED](int *ret, int *bid, int *tid, int *eid)
+{
+       BAT *b, *tb, *eb, *bn;
+       @1 nilval= (@1) @1_nil, *dst, *tbv, *ebv;
+       bit *t;
+       size_t cnt, p;
+
+       @:getBATdescriptor(bid,b,"batcalc.ifThenElse")@
+       
@:getBATdescriptor(tid,tb,"batcalc.ifThenElse",BBPreleaseref(b->batCacheid);)@
+       @:getBATdescriptor(eid,eb,"batcalc.ifThenElse", 
BBPreleaseref(b->batCacheid); BBPreleaseref(tb->batCacheid);)@
+       @:chkSize(b,tb,ifThenElse)@
+       @:chkSize(b,eb,ifThenElse)@
+       @:voidresultBAT([EMAIL PROTECTED],"batcalc.ifThenElse")@
+       bn->tsorted = FALSE;
+       BATkey(BATmirror(bn), FALSE);
+
+       cnt = BATcount(b);
+       t = (bit*) Tloc(b, BUNfirst(b));
+       dst = (@1*)Tloc(bn, BUNfirst(bn));
+       tbv = (@1*)Tloc(tb, BUNfirst(tb));
+       ebv = (@1*)Tloc(eb, BUNfirst(eb));
+
+       for (p=0; p<cnt; p++) {
+               if (t[p] == bit_nil) 
+                       dst[p] = nilval;
+               else if (t[p]) 
+                       dst[p] = tbv[p];
+               else
+                       dst[p] = ebv[p];
+       }
+       BATsetcount(bn, p);
+       BBPreleaseref(tb->batCacheid);
+       BBPreleaseref(eb->batCacheid);
+       @:void_wrapup@
+}
+
+batifthen_export str [EMAIL PROTECTED](int *ret, int *bid, @1 *val, int *eid);
+str
[EMAIL PROTECTED](int *ret, int *bid, @1 *val, int *eid)
+{
+       BAT *b, *eb, *bn;
+       @1 nilval= (@1) @1_nil, *dst, *ebv;
+       bit *t;
+       size_t cnt, p;
+
+       @:getBATdescriptor(bid,b,"batcalc.ifThenElse")@
+       @:getBATdescriptor(eid,eb,"batcalc.ifThenElse", 
BBPreleaseref(b->batCacheid);)@
+       @:chkSize(b,eb,ifThenElse)@
+       @:voidresultBAT([EMAIL PROTECTED],"batcalc.ifThenElse")@
+       bn->tsorted = FALSE;
+       BATkey(BATmirror(bn), FALSE);
+
+       cnt = BATcount(b);
+       t = (bit*) Tloc(b,BUNfirst(b));
+       dst = (@1*)Tloc(bn, BUNfirst(bn));
+       ebv = (@1*)Tloc(eb, BUNfirst(eb));
+
+       for (p=0; p<cnt; p++) {
+               if (t[p] == bit_nil) 
+                       dst[p] = nilval;
+               else if (t[p]) 
+                       dst[p] = *val;
+               else
+                       dst[p] = ebv[p];
+       }
+       BATsetcount(bn, p);
+       BBPreleaseref(eb->batCacheid);
+       @:void_wrapup@
+}
+
+batifthen_export str [EMAIL PROTECTED](int *ret, int *bid, int *tid, @1 *val);
+str
[EMAIL PROTECTED](int *ret, int *bid, int *tid, @1 *val)
+{
+       BAT *b, *tb, *bn;
+       @1 nilval= (@1) @1_nil, *dst, *tbv;
+       bit *t;
+       size_t cnt, p;
+
+       @:getBATdescriptor(bid,b,"batcalc.ifThenElse")@
+       
@:getBATdescriptor(tid,tb,"batcalc.ifThenElse",BBPreleaseref(b->batCacheid);)@
+       @:chkSize(b,tb,ifThenElse)@
+       @:voidresultBAT([EMAIL PROTECTED],"batcalc.ifThenElse")@
+       bn->tsorted = FALSE;
+       BATkey(BATmirror(bn), FALSE);
+
+       cnt = BATcount(b);
+       t = (bit*) Tloc(b,BUNfirst(b));
+       dst = (@1*)Tloc(bn, BUNfirst(bn));
+       tbv = (@1*)Tloc(tb, BUNfirst(tb));
+       
+       for (p=0; p<cnt; p++) {
+               if (t[p] == bit_nil) 
+                       dst[p] = nilval;
+               else if (t[p]) 
+                       dst[p] = tbv[p];
+               else 
+                       dst[p] = *val;
+       }
+       BATsetcount(bn, p);
+       BBPreleaseref(tb->batCacheid);
+       @:void_wrapup@
+}
+@:ifthenImpl(@1)@
[EMAIL PROTECTED]
+#include "mal_config.h"
+#include "batifthen.h"
+
+@:ifthenelseImpl(bit)@
+@:ifthenelseImpl(chr)@
+@:ifthenelseImpl(bte)@
+@:ifthenelseImpl(sht)@
+@:ifthenelseImpl(int)@
+@:ifthenelseImpl(lng)@
+@:ifthenelseImpl(flt)@
+@:ifthenelseImpl(dbl)@
+
[EMAIL PROTECTED] ifthenelseDefault
 batifthen_export str [EMAIL PROTECTED](int *ret, int *bid, @1 *tid, @1 *eid);
 str [EMAIL PROTECTED](int *ret, int *bid, @1 *tid, @1 *eid)
 {
@@ -187,7 +328,9 @@
        bit *t;
 
        @:getBATdescriptor(bid,b,"batcalc.ifThenElse")@
-       @:resBAT(@1,"batcalc.ifThenElse")@
+       @:resultBAT(@1,"batcalc.ifThenElse")@
+       bn->tsorted = FALSE;
+       BATkey(BATmirror(bn), FALSE);
 
        bi = bat_iterator(b);
        t = (bit*)Tloc(b,BUNfirst(b));
@@ -219,7 +362,9 @@
        @:getBATdescriptor(eid,eb,"batcalc.ifThenElse", 
BBPreleaseref(b->batCacheid); BBPreleaseref(tb->batCacheid);)@
        @:chkSize(b,tb,ifThenElse)@
        @:chkSize(b,eb,ifThenElse)@
-       @:resBAT(@1,"batcalc.ifThenElse")@
+       @:resultBAT(@1,"batcalc.ifThenElse")@
+       bn->tsorted = FALSE;
+       BATkey(BATmirror(bn), FALSE);
 
        bi = bat_iterator(b);
        tbi = bat_iterator(tb);
@@ -254,7 +399,9 @@
        @:getBATdescriptor(bid,b,"batcalc.ifThenElse")@
        @:getBATdescriptor(eid,eb,"batcalc.ifThenElse", 
BBPreleaseref(b->batCacheid);)@
        @:chkSize(b,eb,ifThenElse)@
-       @:resBAT(@1,"batcalc.ifThenElse")@
+       @:resultBAT(@1,"batcalc.ifThenElse")@
+       bn->tsorted = FALSE;
+       BATkey(BATmirror(bn), FALSE);
 
        bi = bat_iterator(b);
        ebi = bat_iterator(eb);
@@ -289,38 +436,31 @@
        @:getBATdescriptor(bid,b,"batcalc.ifThenElse")@
        
@:getBATdescriptor(tid,tb,"batcalc.ifThenElse",BBPreleaseref(b->batCacheid);)@
        @:chkSize(b,tb,ifThenElse)@
-       @:resBAT(@1,"batcalc.ifThenElse")@
+       @:resultBAT(@1,"batcalc.ifThenElse")@
+       bn->tsorted = FALSE;
+       BATkey(BATmirror(bn), FALSE);
 
-       if (ATOMvarsized([EMAIL PROTECTED]))
-               val = *(@1**)val;
        bi = bat_iterator(b);
        tbi = bat_iterator(tb);
 
        t = (bit*) Tloc(b,BUNfirst(b));
-
+       
+       if (ATOMvarsized([EMAIL PROTECTED]))
+               val = *(@1**)val;
        BATloop(b, p, q) {
                if (*t == bit_nil) 
-                       BUNfastins(bn, BUNhead(bi,p), (ptr) &nilval);
+                       BUNfastins(bn, NULL, (ptr) &nilval);
                else if (*t) 
-                       BUNfastins(bn, BUNhead(bi,p), BUNtail(tbi, p));
+                       BUNfastins(bn, NULL, BUNtail(tbi, p));
                else
-                       BUNfastins(bn, BUNhead(bi,p), val);
+                       BUNfastins(bn, NULL, val);
                t++;
        }
        BBPreleaseref(tb->batCacheid);
        @:wrapup@
 }
+@:ifthenImpl(@1)@
 @c
-#include "mal_config.h"
-#include "batifthen.h"
-
-@:ifthencstImpl(int)@
-@:ifthencstImpl(sht)@
-@:ifthencstImpl(lng)@
-@:ifthencstImpl(oid)@
-@:ifthencstImpl(flt)@
-@:ifthencstImpl(dbl)@
-@:ifthencstImpl(str)@
-@:ifthencstImpl(chr)@
-@:ifthencstImpl(bit)@
+@:ifthenelseDefault(oid)@
+@:ifthenelseDefault(str)@
 @}

Index: group.mx
===================================================================
RCS file: /cvsroot/monetdb/MonetDB5/src/modules/kernel/group.mx,v
retrieving revision 1.99
retrieving revision 1.100
diff -u -d -r1.99 -r1.100
--- group.mx    20 Nov 2007 13:24:52 -0000      1.99
+++ group.mx    11 Dec 2007 17:32:02 -0000      1.100
@@ -244,6 +244,7 @@
 grp_new(BAT *b, BAT *h)
 {
        if (h) {
+               if (!(h->batDirty&2)) h = BATsetaccess(h, BAT_READ); 
                BATkey(h, TRUE);
                h->tsorted = 0;
                if ((h->hsorted = BAThordered(b)) & 1) {
@@ -258,6 +259,7 @@
        } else {
                assert(h);
        }
+       if (!(b->batDirty&2)) b = BATsetaccess(b, BAT_READ); 
        BBPkeepref(b->batCacheid);
        return GDK_SUCCEED;
 }


-------------------------------------------------------------------------
SF.Net email is sponsored by: 
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Monetdb-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-checkins

Reply via email to