Changeset: 5d9182c26915 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=5d9182c26915
Modified Files:
        gdk/gdk.h
        gdk/gdk_batop.c
Branch: headless
Log Message:

Optionally pass a to-be-filled COL to COLsubselect.
The argument may not be null, but the value it points to may be null,
in which case a new COL is created.


diffs (184 lines):

diff --git a/gdk/gdk.h b/gdk/gdk.h
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -3329,7 +3329,7 @@
 gdk_export COL *COLselect_(COL *b, ptr tl, ptr th, bit li, bit hi);
 gdk_export COL *COLantiselect_(COL *b, ptr tl, ptr th, bit li, bit hi);
 gdk_export COL *COLselect(COL *b, ptr tl, ptr th);
-gdk_export COL *COLsubselect(COL *b, COL *s, ptr tl, ptr th, bit li, bit hi, 
bit anti);
+gdk_export int COLsubselect(COL **ret, COL *b, COL *s, ptr tl, ptr th, bit li, 
bit hi, bit anti);
 
 gdk_export COL *COLconst(oid cnt, int tpe, ptr val);
 gdk_export COL *COLthetajoin(COL *l, COL *r, int mode, oid estimate);
diff --git a/gdk/gdk_batop.c b/gdk/gdk_batop.c
--- a/gdk/gdk_batop.c
+++ b/gdk/gdk_batop.c
@@ -724,8 +724,8 @@
        return NULL;
 }
 
-COL *
-COLsubselect(COL *b, COL *s, ptr tl, ptr th, bit li, bit hi, bit anti)
+int
+COLsubselect(COL **ret, COL *b, COL *s, ptr tl, ptr th, bit li, bit hi, bit 
anti)
 {
        int hval, lval, equi, t, lnil;
        oid offset, batcnt, estimate = 0;
@@ -736,6 +736,8 @@
        assert(li == 0 || li == 1);
        assert(hi == 0 || hi == 1);
 
+       assert(ret);
+       assert(*ret == NULL || (*ret)->type == TYPE_oid || (*ret)->type == 
TYPE_void);
        COLcheck(b, "COLselect");
        COLcheck(tl, "COLselect: tl value required");
        /*
@@ -781,7 +783,9 @@
                         * values are in range, so we need to return
                         * all but, but we also don't want to return
                         * nils, so instead we return nothing. */
-                       return COLnewdensecol(0);
+                       if (*ret == NULL)
+                               *ret = COLnewdensecol(0);
+                       return 0;
                } else if (equi && lnil) {
                        /* antiselect for nil value: turn into range
                         * select for nil-nil range (i.e. everything
@@ -800,15 +804,25 @@
                /* empty range */
                ALGODEBUG THRprintf(GDKout, "#COL_select_(b=%s): empty 
range;\n", COLgetId(b));
 
-               return COLnewdensecol(0);
+               if (*ret == NULL)
+                       *ret = COLnewdensecol(0);
+               return 0;
        }
        if (!equi && !lval && !hval && b->nonil && lnil) {
                bn = COLnewdensecol(b->count);
                bn->seqbase = b->first;
-               return bn;
+               if (*ret) {
+                       *ret = COLappend(*ret, bn, 0);
+                       CBPreclaim(bn);
+                       bn = *ret;
+               }
+               return 0;
        }
-       if (equi && lnil && b->nonil)
-               return COLnewdensecol(0);
+       if (equi && lnil && b->nonil) {
+               if (*ret == NULL)
+                       *ret = COLnewdensecol(0);
+               return 0;
+       }
 
        batcnt = b->count;
 
@@ -892,6 +906,11 @@
                        COL *bn2;
                        bn = COLnewdensecol(low - first);
                        bn->seqbase = first;
+                       if (*ret) {
+                               *ret = COLappend(*ret, bn, 0);
+                               CBPreclaim(bn);
+                               bn = *ret;
+                       }
                        bn2 = COLnewdensecol(COLlast(b) - high);
                        bn->seqbase = high;
                        bn = COLappend(bn, bn2, 1);
@@ -899,12 +918,14 @@
                } else {
                        bn = COLnewdensecol(high - low);
                        bn->seqbase = low;
+                       if (*ret) {
+                               *ret = COLappend(*ret, bn, 0);
+                               CBPreclaim(bn);
+                               bn = *ret;
+                       }
                }
-               /* selected no nils */
-               if (bn != NULL) {
-                       bn->nonil = 1;
-               }
-               return bn;
+               *ret = bn;
+               return 0;
        }
        /*
         * @-
@@ -921,11 +942,10 @@
 
                tmp1 = COLslice(b, _lo, _hi);   /* slice keeps all parent 
properties */
                if (tmp1) {
-                       COL *tmp2;
+                       COL *tmp2 = NULL;
                        ALGODEBUG THRprintf(GDKout, "#COL_select_(b=%s): 
sampling: tmp2 = COL_select_(tmp1=%s, tl, th, tail);\n", COLgetId(b), 
COLgetId(tmp1));
 
-                       tmp2 = COLsubselect(tmp1, NULL, tl, th, li, hi, anti);
-                       if (tmp2) {
+                       if (COLsubselect(&tmp2, tmp1, NULL, tl, th, li, hi, 
anti) == 0) {
                                /* reserve 105% of what has been estimated */
                                estimate = (oid) ((((lng) tmp2->count) * (lng) 
batcnt) / LL_CONSTANT(100));
                                CBPreclaim(tmp2);
@@ -939,7 +959,10 @@
         * @-
         * Create the result COL and execute the select algorithm.
         */
-       bn = COLnew(TYPE_oid, estimate);
+       if (*ret)
+               bn = *ret;
+       else
+               bn = COLnew(TYPE_oid, estimate);
        if (bn) {
                int nocheck = (estimate >= batcnt);
 
@@ -970,31 +993,44 @@
        ESTIDEBUG THRprintf(GDKout, "#COL_select_(b=%s): resultsize: estimated 
" OIDFMT ", got " OIDFMT ".\n",
                            COLgetId(b), estimate, bn->count);
 
-       return bn;
+       *ret = bn;
+       return 0;
 }
 
 COL *
 COL_select_(COL *b, ptr tl, ptr th, bit li, bit hi, bit anti)
 {
-       return COLsubselect(b, NULL, tl, th, li, hi, anti);
+       COL *bn = NULL;
+       if (COLsubselect(&bn, b, NULL, tl, th, li, hi, anti) == 0)
+               return bn;
+       return NULL;
 }
 
 COL *
 COLselect_(COL *b, ptr l, ptr h, bit li, bit hi)
 {
-       return COLsubselect(b, NULL, l, h, li, hi, FALSE);
+       COL *bn = NULL;
+       if (COLsubselect(&bn, b, NULL, l, h, li, hi, FALSE) == 0)
+               return bn;
+       return NULL;
 }
 
 COL *
 COLantiselect_(COL *b, ptr l, ptr h, bit li, bit hi)
 {
-       return COLsubselect(b, NULL, l, h, li, hi, TRUE);
+       COL *bn = NULL;
+       if (COLsubselect(&bn, b, NULL, l, h, li, hi, TRUE) == 0)
+               return bn;
+       return NULL;
 }
 
 COL *
 COLselect(COL *b, ptr l, ptr h)
 {
-       return COLsubselect(b, NULL, l, h, TRUE, TRUE, FALSE);
+       COL *bn = NULL;
+       if (COLsubselect(&bn, b, NULL, l, h, TRUE, TRUE, FALSE) == 0)
+               return bn;
+       return NULL;
 }
 
 /*
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to