Changeset: a271392a7006 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=a271392a7006
Modified Files:
        gdk/gdk.h
        gdk/gdk_atoms.c
        monetdb5/modules/kernel/Makefile.ag
        monetdb5/modules/kernel/colcast.c.mx
        monetdb5/modules/kernel/colcast.h.mx
        monetdb5/modules/kernel/colcast.mal.mx
        monetdb5/modules/kernel/colcast.mx
Branch: headless
Log Message:

Added a COL string put
and converted the colcast file.


diffs (truncated from 1031 to 300 lines):

diff --git a/gdk/gdk.h b/gdk/gdk.h
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -2895,6 +2895,7 @@
 
 #define COLforloop(b,o) for( o = 0; o < b->count; o++)
 #define COLgetString(b,o)      (str)(base(b) + ((size_t) 
VarHeapValRaw(b,o,b->width)  << GDK_VARSHIFT))
+gdk_export str COLputString(COL *b, oid o, str v);
 
 /*
  * batloop where the current element can be deleted/updated
diff --git a/gdk/gdk_atoms.c b/gdk/gdk_atoms.c
--- a/gdk/gdk_atoms.c
+++ b/gdk/gdk_atoms.c
@@ -758,6 +758,35 @@
 #define mult10(x)      ((x) + (x) + ((x) << 3))
 #define mult7(x)       (((x) << 3) - (x))
 
+str COLputString(COL *b, oid o, str v) {
+       var_t _d;                                       
+       
+       if ((b)->varsized && (b)->type) {                       
+               ATOMput((b)->type, (b)->vheap, &_d, v);         
+               if ((b)->width < SIZEOF_VAR_T &&                
+                       ((b)->width <= 2 ? _d - GDK_VAROFFSET : _d) >= 
((size_t) 1 << (8 * (b)->width))) { 
+                       /* doesn't fit in current heap, upgrade it */ 
+                       COLaccessBegin(b, USE_HEAP, MMAP_SEQUENTIAL); 
+                       GDKupgradevarheap((b), _d, o);  
+                       COLaccessEnd(b, USE_HEAP, MMAP_SEQUENTIAL);     
+               }                                               
+               switch ((b)->width) {                           
+               case 1:                                         
+                       ((unsigned char *)b->heap)[o] = (unsigned char) (_d - 
GDK_VAROFFSET); 
+                       break;                                  
+               case 2:                                         
+                       ((unsigned short *)b->heap)[o] = (unsigned short) (_d - 
GDK_VAROFFSET); 
+                       break;                                  
+               case 4:                                         
+                       ((unsigned int *)b->heap)[o] = (unsigned int) (_d - 
GDK_VAROFFSET); 
+                       break;                                  
+               case 8:                                         
+                       ((unsigned lng *)b->heap)[o] = (unsigned lng) _d ; 
+                       break;                                  
+               }                                               
+       } 
+       return MAL_SUCCEED;
+ }
 int
 voidFromStr(str src, int *len, void **dst)
 {
diff --git a/monetdb5/modules/kernel/Makefile.ag 
b/monetdb5/modules/kernel/Makefile.ag
--- a/monetdb5/modules/kernel/Makefile.ag
+++ b/monetdb5/modules/kernel/Makefile.ag
@@ -45,7 +45,9 @@
                colcalc.mal.mx \
                colcalc.h.mx \
                colcalc.c.mx \
-#              colcast.mx \
+               colcast.mal.mx \
+               colcast.h.mx \
+               colcast.c.mx \
 #              colcolor.mx \
 #              colifthen.mx \
 #              colmmath.mx \
@@ -68,7 +70,7 @@
        DIR = libdir/monetdb5
        SOURCES = calc.mx column.mx algebra.mx status.mal unix.mal \
                mmath.mx lock.mal sema.mal alarm.mx colstr.mx colmtime.mx \
-               colcolor.mx colifthen.mx colcast.mx colcalc.mal.mx colmmath.mx \
+               colcolor.mx colifthen.mx colcast.mal.mx colcalc.mal.mx 
colmmath.mx \
                group.mx aggr.mx array.mx \
                mx logger.mal microbenchmark.mx
 }
diff --git a/monetdb5/modules/kernel/colcast.c.mx 
b/monetdb5/modules/kernel/colcast.c.mx
new file mode 100644
--- /dev/null
+++ b/monetdb5/modules/kernel/colcast.c.mx
@@ -0,0 +1,274 @@
+/*
+ * The contents of this file are subject to the MonetDB Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://monetdb.cwi.nl/Legal/MonetDBLicense-1.1.html
+ * 
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ * 
+ * The Original Code is the MonetDB Database System.
+ * 
+ * The Initial Developer of the Original Code is CWI.
+ * Portions created by CWI are Copyright (C) 1997-July 2008 CWI.
+ * Copyright August 2008-2011 MonetDB B.V.
+ * All Rights Reserved.
+*/
+
+@f colcast
+/* M.L. Kersten
+ * BAT Coercion Routines
+ * The coercion routines over BATs can not easily be speed up using
+ * an accumulator approach, because they often require different storage 
space. 
+ * Nevertheless, the implementation provided here are much faster compared
+ * to the Version 4.* implementation.
+ * 
+ * The coercion routines are build for speed. They are not protected
+ * against overflow.
+*/
+#include "colcast.h"
+/* #include "math.h"
+#include "mal_exception.h" */
+
+/*
+ * The different coercion implementations exploit the fact
+ * that many coercions are simply space enlargers.
+ * The others effectively may loose information, which calls
+ * for a more expensive operation based on the conversion
+ * routines in the GDK kernel.
+*/
+
+@= Idempotent
+str CMDconvert_@1(int *ret, int *l)
+{
+    COL *bl, *bn;
+   
+    if ( getCOLdescriptor(&bl,l) != MAL_SUCCEED )
+        throw(MAL,"colcalc.@1",MAL_MALLOC_FAIL);
+
+       bn = COLcopy(bl, bl->type, 0);
+       CBPreleaseref(bl);
+    if ( bn == NULL )
+        throw(MAL,"colcalc.@1",MAL_MALLOC_FAIL);
+       *ret = CBPkeepref( bn);
+       return MAL_SUCCEED;
+}
+@-
+@= GeneralFixed
+str CMDconvert_@1_@2(int *ret, int *l)
+{
+       oid o;
+    COL *bl, *bn;
+       @1 *lbase;
+       @2 *nbase;
+   
+    if ( getCOLdescriptor(&bl,l) != MAL_SUCCEED )
+        throw(MAL,"colcalc.@1",MAL_MALLOC_FAIL);
+    if ( (bn = COLnew(TYPE_@2, COLcount(bl)) ) == NULL ) {
+        CBPreleaseref(bl);
+        throw(MAL,"colcalc.@1",MAL_MALLOC_FAIL);
+    }
+
+       lbase = (@1* ) getCOLbase(bl);
+       nbase = (@2*) getCOLbase(bn);
+
+       COLaccessBegin(bl, USE_HEAP, MMAP_SEQUENTIAL);
+       if (bl->nonil)
+               COLforloop(bl,o)
+                       nbase[o] = (@2) lbase[o];
+       else
+               COLforloop(bl,o)
+                       if (lbase[o] == @1_nil) {
+                               nbase[o] = @2_nil;
+                               bn->nonil = 0;
+                       } else
+                               nbase[o] = (@2) lbase[o];
+       COLaccessEnd(bl, USE_HEAP, MMAP_SEQUENTIAL);
+
+       COLsetcount(bn, COLcount(bl));
+       COLsetreadonly(bn);
+       bn->sorted = 0;
+
+       *ret = CBPkeepref( bn);
+       CBPreleaseref(bl);
+       return MAL_SUCCEED;
+}
+@= GeneralStr
+str CMDconvert_@1_str(int *ret, int *l)
+{
+    COL *bl, *bn;
+       oid o;
+       @1 *lbase;
+       oid *nbase;
+   
+    if ( getCOLdescriptor(&bl,l) != MAL_SUCCEED )
+        throw(MAL,"colcalc.@1",MAL_MALLOC_FAIL);
+    if ( (bn = COLnew(TYPE_str, COLcount(bl)) ) == NULL ) {
+        CBPreleaseref(bl);
+        throw(MAL,"colcalc.@1",MAL_MALLOC_FAIL);
+    }
+
+       lbase = (@1*) getCOLbase(bl);
+       nbase = (oid*) getCOLbase(bn);
+
+
+       COLaccessBegin(bl, USE_HEAP, MMAP_SEQUENTIAL);
+       COLforloop(bl,o){
+               str dst=0;
+               int len=0;
+               @1 v = lbase[o];
+
+               @1ToStr(&dst, &len, (ptr) &v);
+               COLputString(bl,o,dst);
+               if (dst) 
+                       GDKfree(dst);
+       }
+       COLsetcount(bn, COLcount(bl));
+       COLaccessEnd(bl, USE_HEAP, MMAP_SEQUENTIAL);
+       COLsetreadonly(bn);
+       bn->sorted = 0;
+
+       *ret = CBPkeepref( bn);
+       CBPreleaseref(bl);
+       return MAL_SUCCEED;
+}
+
+str CMDconvert_str_@1(int *ret, int *l)
+{
+    COL *bl, *bn;
+       oid o;
+       @1 *nbase;
+       ptr v = NULL; 
+       int len = 0;
+   
+    if ( getCOLdescriptor(&bl,l) != MAL_SUCCEED )
+        throw(MAL,"colcalc.@1",MAL_MALLOC_FAIL);
+    if ( (bn = COLnew(TYPE_@1, COLcount(bl)) ) == NULL ) {
+        CBPreleaseref(bl);
+        throw(MAL,"colcalc.@1",MAL_MALLOC_FAIL);
+    }
+
+       nbase = (@1*) getCOLbase(bn);
+
+       COLaccessBegin(bl, USE_HEAP, MMAP_SEQUENTIAL);
+       COLforloop(bl,o){
+               ATOMfromstr(TYPE_@1, &v, &len, (char *) COLgetString(bl, o));
+               nbase[o] = *(@1*)v;
+       }
+       COLaccessEnd(bl, USE_HEAP, MMAP_SEQUENTIAL);
+       if(v) GDKfree(v);
+       COLsetcount(bn, COLcount(bl));
+       COLsetreadonly(bn);
+       bn->sorted = 0;
+
+       *ret = CBPkeepref( bn);
+       CBPreleaseref(bl);
+       return MAL_SUCCEED;
+}
+@= CoercionEnlarge
+       @:GeneralFixed(@1,@2)@
+@= CoercionReduce
+       @:GeneralFixed(@1,@2)@
+@c
+#include "monetdb_config.h"
+#include "colcast.h"
+
+int    oidToStr(char **dst, int *len, oid *src  ){
+               return OIDtoStr(dst,len, src);
+}
+       @:Idempotent(bit)@
+       @:Idempotent(chr)@
+       @:Idempotent(bte)@
+       @:Idempotent(sht)@
+       @:Idempotent(int)@
+       @:Idempotent(oid)@
+       @:Idempotent(wrd)@
+       @:Idempotent(lng)@
+       @:Idempotent(flt)@
+       @:Idempotent(dbl)@
+       @:Idempotent(str)@
+
+       @:GeneralStr(bit)@
+       @:GeneralStr(chr)@
+       @:GeneralStr(bte)@
+       @:GeneralStr(sht)@
+       @:GeneralStr(int)@
+       @:GeneralStr(lng)@
+       @:GeneralStr(flt)@
+       @:GeneralStr(dbl)@
+
+       @:CoercionEnlarge(bte,sht)@
+       @:CoercionEnlarge(bte,oid)@
+       @:CoercionEnlarge(bte,int)@
+       @:CoercionEnlarge(bte,wrd)@
+       @:CoercionEnlarge(bte,lng)@
+       @:CoercionEnlarge(bte,flt)@
+       @:CoercionEnlarge(bte,dbl)@
+
+       @:CoercionReduce(sht,bte)@
+       @:CoercionEnlarge(sht,oid)@
+       @:CoercionEnlarge(sht,int)@
+       @:CoercionEnlarge(sht,wrd)@
+       @:CoercionEnlarge(sht,lng)@
+       @:CoercionEnlarge(sht,flt)@
+       @:CoercionEnlarge(sht,dbl)@
+
+       @:CoercionReduce(int,bte)@
+       @:CoercionReduce(int,sht)@
+       @:CoercionEnlarge(int,oid)@
+       @:CoercionEnlarge(int,wrd)@
+       @:CoercionEnlarge(int,lng)@
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to