Changeset: 4878c95ec398 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=4878c95ec398
Added Files:
        gdk/gdk_cross.c
Removed Files:
        gdk/gdk_relop.mx
Modified Files:
        clients/Tests/exports.stable.out
        gdk/Makefile.ag
        gdk/gdk.h
        monetdb5/modules/kernel/algebra.mx
Branch: default
Log Message:

Reimplemented BATcross, got rid of yet another .mx file.


diffs (truncated from 496 to 300 lines):

diff --git a/clients/Tests/exports.stable.out b/clients/Tests/exports.stable.out
--- a/clients/Tests/exports.stable.out
+++ b/clients/Tests/exports.stable.out
@@ -107,6 +107,7 @@ BAT *BATcopy(BAT *b, int ht, int tt, int
 BUN BATcount(BAT *b);
 BUN BATcount_no_nil(BAT *b);
 BAT *BATcross(BAT *l, BAT *r);
+gdk_return BATcross1(BAT **r1p, BAT **r2p, BAT *l, BAT *r);
 BAT *BATdel(BAT *b, BAT *c, bit force);
 BAT *BATdelHead(BAT *b, BAT *c, bit force);
 int BATdelete(BAT *b);
@@ -192,6 +193,7 @@ BAT *BATsort(BAT *b);
 BAT *BATsort_rev(BAT *b);
 BAT *BATssort(BAT *b);
 BAT *BATssort_rev(BAT *b);
+gdk_return BATsubcross(BAT **r1p, BAT **r2p, BAT *l, BAT *r, BAT *sl, BAT *sr);
 gdk_return BATsubjoin(BAT **r1p, BAT **r2p, BAT *l, BAT *r, BAT *sl, BAT *sr, 
BUN estimate);
 gdk_return BATsubleftfetchjoin(BAT **r1p, BAT **r2p, BAT *l, BAT *r, BAT *sl, 
BAT *sr, BUN estimate);
 gdk_return BATsubleftjoin(BAT **r1p, BAT **r2p, BAT *l, BAT *r, BAT *sl, BAT 
*sr, BUN estimate);
diff --git a/gdk/Makefile.ag b/gdk/Makefile.ag
--- a/gdk/Makefile.ag
+++ b/gdk/Makefile.ag
@@ -30,7 +30,7 @@ lib_gdk = {
                gdk_atoms.c gdk_atoms.h \
                gdk_qsort.c gdk_qsort_impl.h gdk_ssort.c gdk_ssort_impl.h \
                gdk_storage.c gdk_bat.c \
-               gdk_delta.c gdk_relop.mx gdk_system.c gdk_value.c \
+               gdk_delta.c gdk_cross.c gdk_system.c gdk_value.c \
                gdk_rangejoin.mx \
                gdk_posix.c gdk_logger.c gdk_sample.c \
                gdk_private.h gdk_delta.h gdk_logger.h gdk_posix.h \
diff --git a/gdk/gdk.h b/gdk/gdk.h
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -3151,6 +3151,8 @@ gdk_export BAT *BATjoin(BAT *l, BAT *r, 
 gdk_export BAT *BATantijoin(BAT *l, BAT *r);
 gdk_export BAT *BATleftjoin(BAT *l, BAT *r, BUN estimate);
 gdk_export BAT *BATouterjoin(BAT *l, BAT *r, BUN estimate);
+gdk_export gdk_return BATcross1(BAT **r1p, BAT **r2p, BAT *l, BAT *r);
+gdk_export gdk_return BATsubcross(BAT **r1p, BAT **r2p, BAT *l, BAT *r, BAT 
*sl, BAT *sr);
 gdk_export BAT *BATcross(BAT *l, BAT *r);
 
 gdk_export gdk_return BATsubleftjoin(BAT **r1p, BAT **r2p, BAT *l, BAT *r, BAT 
*sl, BAT *sr, BUN estimate);
diff --git a/gdk/gdk_cross.c b/gdk/gdk_cross.c
new file mode 100644
--- /dev/null
+++ b/gdk/gdk_cross.c
@@ -0,0 +1,142 @@
+/*
+ * 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://www.monetdb.org/Legal/MonetDBLicense
+ *
+ * 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-2013 MonetDB B.V.
+ * All Rights Reserved.
+ */
+
+#include "monetdb_config.h"
+#include "gdk.h"
+#include "gdk_private.h"
+
+gdk_return
+BATcross1(BAT **r1p, BAT **r2p, BAT *l, BAT *r)
+{
+       BAT *bn1, *bn2;
+       BUN i, j;
+       oid *p1, *p2;
+
+       assert(BAThdense(l));
+       assert(BAThdense(r));
+       bn1 = BATnew(TYPE_void, TYPE_oid, BATcount(l) * BATcount(r));
+       bn2 = BATnew(TYPE_void, TYPE_oid, BATcount(l) * BATcount(r));
+       if (bn1 == NULL || bn2 == NULL) {
+               if (bn1 != NULL)
+                       BBPreclaim(bn1);
+               if (bn2 != NULL)
+                       BBPreclaim(bn2);
+               return GDK_FAIL;
+       }
+       BATseqbase(bn1, 0);
+       BATseqbase(bn2, 0);
+       p1 = (oid *) Tloc(bn1, BUNfirst(bn1));
+       p2 = (oid *) Tloc(bn2, BUNfirst(bn2));
+       for (i = 0; i < BATcount(l); i++) {
+               for (j = 0; j < BATcount(r); j++) {
+                       *p1++ = i + l->hseqbase;
+                       *p2++ = j + r->hseqbase;
+               }
+       }
+       BATsetcount(bn1, BATcount(l) * BATcount(r));
+       BATsetcount(bn2, BATcount(l) * BATcount(r));
+       bn1->tsorted = 1;
+       bn1->trevsorted = BATcount(l) <= 1;
+       bn1->tkey = BATcount(r) <= 1;
+       bn1->tdense = bn1->tkey != 0;
+       bn1->T->nil = 0;
+       bn1->T->nonil = 1;
+       bn2->tsorted = BATcount(l) <= 1;
+       bn2->trevsorted = BATcount(bn2) <= 1;
+       bn2->tkey = BATcount(l) <= 1;
+       bn2->tdense = bn2->tkey != 0;
+       bn2->T->nil = 0;
+       bn2->T->nonil = 1;
+       *r1p = bn1;
+       *r2p = bn2;
+       return GDK_SUCCEED;
+}
+
+gdk_return
+BATsubcross(BAT **r1p, BAT **r2p, BAT *l, BAT *r, BAT *sl, BAT *sr)
+{
+       BAT *bn1, *bn2, *t;
+
+       if (BATcross1(&bn1, &bn2, sl ? sl : l, sr ? sr : r) == GDK_FAIL)
+               return GDK_FAIL;
+       if (sl) {
+               t = BATproject(bn1, sl);
+               BBPunfix(bn1->batCacheid);
+               if (t == NULL) {
+                       BBPunfix(bn2->batCacheid);
+                       return GDK_FAIL;
+               }
+               bn1 = t;
+       }
+       if (sr) {
+               t = BATproject(bn2, sr);
+               BBPunfix(bn2->batCacheid);
+               if (t == NULL) {
+                       BBPunfix(bn1->batCacheid);
+                       return GDK_FAIL;
+               }
+               bn2 = t;
+       }
+       *r1p = bn1;
+       *r2p = bn2;
+       return GDK_SUCCEED;
+}
+
+BAT *
+BATcross(BAT *l, BAT *r)
+{
+       BAT *bn1, *bn2, *t;
+
+       l = BATmirror(BATmark(l, 0));
+       if (l == NULL)
+               return NULL;
+       r = BATmirror(BATmark(BATmirror(r), 0));
+       if (r == NULL) {
+               BBPunfix(l->batCacheid);
+               return NULL;
+       }
+
+       if (BATcross1(&bn1, &bn2, l, r) == GDK_FAIL)
+               goto bailout;
+       t = BATproject(bn1, l);
+       BBPunfix(bn1->batCacheid);
+       if (t == NULL) {
+               BBPunfix(bn2->batCacheid);
+               goto bailout;
+       }
+       bn1 = t;
+       t = BATproject(bn2, r);
+       BBPunfix(bn2->batCacheid);
+       if (t == NULL) {
+               BBPunfix(bn1->batCacheid);
+               goto bailout;
+       }
+       bn2 = t;
+       BBPunfix(l->batCacheid);
+       BBPunfix(r->batCacheid);
+       t = VIEWcreate(BATmirror(bn1), bn2);
+       BBPunfix(bn1->batCacheid);
+       BBPunfix(bn2->batCacheid);
+       return t;
+
+  bailout:
+       BBPunfix(l->batCacheid);
+       BBPunfix(r->batCacheid);
+       return NULL;
+}
diff --git a/gdk/gdk_relop.mx b/gdk/gdk_relop.mx
deleted file mode 100644
--- a/gdk/gdk_relop.mx
+++ /dev/null
@@ -1,261 +0,0 @@
-@/
-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://www.monetdb.org/Legal/MonetDBLicense
-
-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-2013 MonetDB B.V.
-All Rights Reserved.
-@
-
-@f gdk_relop
-
-@c
-/*
- * @a M. L. Kersten, P. Boncz, S. Manegold
- * @* BAT relational operators
- * The basic relational operators are implemented for BATs.
- * Particular attention has been paid to speed-up processing
- * joins, such that navigational access and object re-assembly
- * are not being harmed too much.
- */
-#include "monetdb_config.h"
-#include "gdk.h"
-#include "gdk_private.h"
-
-#define SAMPLE_TRESHOLD_LOG 17
-#define SAMPLE_SLICE_SIZE 1000
-
-/*
- * @+ Join Algorithms
- * All join related operations have the same prelude to check
- * domain compatibility and to creates the BAT to hold the result.
- *
- * We do some dynamic effort to estimate the result size. Good
- * estimates enhance performance and reduce the memory hunger of the join.
- * Method: we sample on l, and join on the whole r. This macro is called by
- * the physical join algorithms, hence we already decided on the algorithm
- * and join method, so the initial costs on r (e.g. hash creation) would have
- * to be paid anyway, and are reused later in the real join phase.
- *
- * Sampling was made more robust by using a logarithmic number of slices
- * taken at equal-spaced intervals across l. The results are then analyzed
- * and checked for outliers. If outliers are present, a real sample is taken
- * and executed with the generic join algorithm to obtain an better estimate.
- *
- * On small joins we just assume 1-N joins with a limited (=3) hit rate.
- */
-
-#define HLATOMput(bn, dst) ATOMput(bn->htype, bn->H->vheap, dst, 
BUNhloc(li,l_cur))
-#define HVATOMput(bn, dst) Hputvalue(bn, dst, BUNhvar(li,l_cur), 1)
-#define TLATOMput(bn, dst) ATOMput(bn->ttype, bn->T->vheap, dst, 
BUNtloc(ri,r_cur))
-#define TVATOMput(bn, dst) Tputvalue(bn, dst, BUNtvar(ri,r_cur), 1)
-#define LATOM_cmp(bn, p,n) atom_CMP(p, n, bn->ttype)
-#define VATOM_cmp(bn, p,n) atom_CMP(p, n, bn->ttype)
-
-@= SIMPLEput
-#define H@1put(bn,dst) *(@1*) (dst) = *(@1*) (BUNhloc(li,l_cur))
-#define T@1put(bn,dst) *(@1*) (dst) = *(@1*) (BUNtloc(ri,r_cur))
-#define @1_cmp(bn,p,n)  simple_CMP(p, n, @1)
-@
-@c
-@:SIMPLEput(bte)@
-@:SIMPLEput(sht)@
-@:SIMPLEput(int)@
-@:SIMPLEput(flt)@
-@:SIMPLEput(lng)@
-@:SIMPLEput(dbl)@
-
-@c
-/*
- * @+ Cross Product
- * This operation computes the cross product of two BATs, returning only the
- * head-value from the 'left' operand and then tail-value from the 'right'
- * operand.
- */
-@= cross2
-static BAT *
-cross_@1_@2(BAT *bn, BAT *l, BAT *r)
-{
-       BATiter li = bat_iterator(l);
-       BATiter ri = bat_iterator(r);
-       BATiter bni;
-       BUN l_cur, l_end, r_cur, r_end, dst;
-
-       /* Just to silence compilers (Intel's icc) that otherwise might
-        * complain about "declared but never referenced" labels
-        * (condition should never be true).
-        * (A "dead" goto between the return and the label makes (other)
-        * compilers (Sun) complain about never reached code...)
-        */
-       if (!bn)
-               goto bunins_failed;
-
-       bni = bat_iterator(bn);
-       dst = BUNfirst(bn);
-       ALGODEBUG fprintf(stderr, "#BATcross: cross_@1_@2();\n");
_______________________________________________
checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to