Changeset: e4bc64bf16d3 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=e4bc64bf16d3
Added Files:
        gdk/gdk_project.c
Modified Files:
        gdk/Makefile.ag
        gdk/gdk_join.c
Branch: default
Log Message:

Moved BATproject into its own file gdk_project.c.


diffs (truncated from 857 to 300 lines):

diff --git a/gdk/Makefile.ag b/gdk/Makefile.ag
--- a/gdk/Makefile.ag
+++ b/gdk/Makefile.ag
@@ -27,7 +27,7 @@ lib_gdk = {
                gdk_calc.c gdk_calc.h gdk_calc_compare.h gdk_calc_private.h \
                gdk_aggr.c gdk_group.c \
                gdk_imprints.c gdk_imprints.h \
-               gdk_join.c \
+               gdk_join.c gdk_project.c \
                gdk_unique.c \
                gdk_firstn.c \
                bat.feps bat1.feps bat2.feps \
diff --git a/gdk/gdk_join.c b/gdk/gdk_join.c
--- a/gdk/gdk_join.c
+++ b/gdk/gdk_join.c
@@ -12,12 +12,12 @@
 #include "gdk_calc_private.h"
 
 /*
- * All "sub" join variants produce some sort of join on two input
- * BATs, optionally subject to up to two candidate lists.  Only values
- * in the input BATs that are mentioned in the associated candidate
- * list (if provided) are eligible.  They all return two output BATs
- * in the first two arguments.  The join operations differ in the way
- * in which tuples from the two inputs are matched.
+ * All join variants produce some sort of join on two input BATs,
+ * optionally subject to up to two candidate lists.  Only values in
+ * the input BATs that are mentioned in the associated candidate list
+ * (if provided) are eligible.  They all return two output BATs in the
+ * first two arguments.  The join operations differ in the way in
+ * which tuples from the two inputs are matched.
  *
  * All inputs BATs must be dense headed, the output BATs will also be
  * dense headed.  The outputs consist of two aligned BATs (i.e. same
@@ -62,16 +62,12 @@
  *     right values; two extra Boolean parameters, li and hi,
  *     indicate whether equal values match
  *
- * In addition to these functions, there are two more functions that
- * are closely related:
+ * In addition to these functions, there is one more functions that is
+ * closely related:
  * BATdiff
  *     difference: return a candidate list compatible list of OIDs of
  *     tuples in the left input whose value does not occur in the
  *     right input
- * BATproject
- *     projection: return a BAT aligned with the left input whose
- *     values are the values from the right input that were referred
- *     to by the OIDs in the tail of the left input
  */
 
 /* Perform a bunch of sanity checks on the inputs to a join. */
@@ -3478,392 +3474,3 @@ BATrangejoin(BAT **r1p, BAT **r2p, BAT *
         * it uses the imprints code there */
        return rangejoin(r1, r2, l, rl, rh, sl, sr, li, hi, maxsize);
 }
-
-#define project_loop(TYPE)                                             \
-static gdk_return                                                      \
-project_##TYPE(BAT *bn, BAT *l, BAT *r, int nilcheck)                  \
-{                                                                      \
-       oid lo, hi;                                                     \
-       const TYPE *restrict rt;                                        \
-       TYPE *restrict bt;                                              \
-       TYPE v;                                                         \
-       const oid *restrict o;                                          \
-       oid rseq, rend;                                                 \
-                                                                       \
-       o = (const oid *) Tloc(l, BUNfirst(l));                         \
-       rt = (const TYPE *) Tloc(r, BUNfirst(r));                       \
-       bt = (TYPE *) Tloc(bn, BUNfirst(bn));                           \
-       rseq = r->hseqbase;                                             \
-       rend = rseq + BATcount(r);                                      \
-       lo = 0;                                                         \
-       hi = lo + BATcount(l);                                          \
-       if (nilcheck) {                                                 \
-               for (; lo < hi; lo++) {                                 \
-                       if (o[lo] < rseq || o[lo] >= rend) {            \
-                               if (o[lo] == oid_nil) {                 \
-                                       bt[lo] = TYPE##_nil;            \
-                                       bn->T->nonil = 0;               \
-                                       bn->T->nil = 1;                 \
-                                       bn->tsorted = 0;                \
-                                       bn->trevsorted = 0;             \
-                                       bn->tkey = 0;                   \
-                                       lo++;                           \
-                                       break;                          \
-                               } else {                                \
-                                       GDKerror("BATproject: does not match 
always\n"); \
-                                       return GDK_FAIL;                \
-                               }                                       \
-                       } else {                                        \
-                               v = rt[o[lo] - rseq];                   \
-                               bt[lo] = v;                             \
-                               if (v == TYPE##_nil && bn->T->nonil) { \
-                                       bn->T->nonil = 0;               \
-                                       bn->T->nil = 1;                 \
-                                       lo++;                           \
-                                       break;                          \
-                               }                                       \
-                       }                                               \
-               }                                                       \
-       }                                                               \
-       for (; lo < hi; lo++) {                                         \
-               if (o[lo] < rseq || o[lo] >= rend) {                    \
-                       if (o[lo] == oid_nil) {                         \
-                               bt[lo] = TYPE##_nil;                    \
-                               bn->T->nonil = 0;                       \
-                               bn->T->nil = 1;                         \
-                               bn->tsorted = 0;                        \
-                               bn->trevsorted = 0;                     \
-                               bn->tkey = 0;                           \
-                       } else {                                        \
-                               GDKerror("BATproject: does not match 
always\n"); \
-                               return GDK_FAIL;                        \
-                       }                                               \
-               } else {                                                \
-                       v = rt[o[lo] - rseq];                           \
-                       bt[lo] = v;                                     \
-               }                                                       \
-       }                                                               \
-       assert((BUN) lo == BATcount(l));                                \
-       BATsetcount(bn, (BUN) lo);                                      \
-       return GDK_SUCCEED;                                             \
-}
-
-
-/* project type switch */
-project_loop(bte)
-project_loop(sht)
-project_loop(int)
-project_loop(flt)
-project_loop(dbl)
-project_loop(lng)
-#ifdef HAVE_HGE
-project_loop(hge)
-#endif
-
-static gdk_return
-project_void(BAT *bn, BAT *l, BAT *r)
-{
-       oid lo, hi;
-       oid *restrict bt;
-       const oid *o;
-       oid rseq, rend;
-
-       assert(r->tseqbase != oid_nil);
-       o = (const oid *) Tloc(l, BUNfirst(l));
-       bt = (oid *) Tloc(bn, BUNfirst(bn));
-       bn->tsorted = l->tsorted;
-       bn->trevsorted = l->trevsorted;
-       bn->tkey = l->tkey & 1;
-       bn->T->nonil = 1;
-       bn->T->nil = 0;
-       rseq = r->hseqbase;
-       rend = rseq + BATcount(r);
-       for (lo = 0, hi = lo + BATcount(l); lo < hi; lo++) {
-               if (o[lo] < rseq || o[lo] >= rend) {
-                       if (o[lo] == oid_nil) {
-                               bt[lo] = oid_nil;
-                               bn->T->nonil = 0;
-                               bn->T->nil = 1;
-                               bn->tsorted = 0;
-                               bn->trevsorted = 0;
-                               bn->tkey = 0;
-                       } else {
-                               GDKerror("BATproject: does not match always\n");
-                               return GDK_FAIL;
-                       }
-               } else {
-                       bt[lo] = o[lo] - rseq + r->tseqbase;
-               }
-       }
-       assert((BUN) lo == BATcount(l));
-       BATsetcount(bn, (BUN) lo);
-       return GDK_SUCCEED;
-}
-
-static gdk_return
-project_any(BAT *bn, BAT *l, BAT *r, int nilcheck)
-{
-       BUN n;
-       oid lo, hi;
-       BATiter ri;
-       int (*cmp)(const void *, const void *) = ATOMcompare(r->ttype);
-       const void *nil = ATOMnilptr(r->ttype);
-       const void *v;
-       const oid *o;
-       oid rseq, rend;
-
-       o = (const oid *) Tloc(l, BUNfirst(l));
-       n = BUNfirst(bn);
-       ri = bat_iterator(r);
-       rseq = r->hseqbase;
-       rend = rseq + BATcount(r);
-       for (lo = 0, hi = lo + BATcount(l); lo < hi; lo++, n++) {
-               if (o[lo] < rseq || o[lo] >= rend) {
-                       if (o[lo] == oid_nil) {
-                               tfastins_nocheck(bn, n, nil, Tsize(bn));
-                               bn->T->nonil = 0;
-                               bn->T->nil = 1;
-                               bn->tsorted = 0;
-                               bn->trevsorted = 0;
-                               bn->tkey = 0;
-                       } else {
-                               GDKerror("BATproject: does not match always\n");
-                               goto bunins_failed;
-                       }
-               } else {
-                       v = BUNtail(ri, o[lo] - rseq + BUNfirst(r));
-                       tfastins_nocheck(bn, n, v, Tsize(bn));
-                       if (nilcheck && bn->T->nonil && cmp(v, nil) == 0) {
-                               bn->T->nonil = 0;
-                               bn->T->nil = 1;
-                       }
-               }
-       }
-       assert(n == BATcount(l));
-       BATsetcount(bn, n);
-       return GDK_SUCCEED;
-bunins_failed:
-       return GDK_FAIL;
-}
-
-BAT *
-BATproject(BAT *l, BAT *r)
-{
-       BAT *bn;
-       oid lo, hi;
-       gdk_return res;
-       int tpe = ATOMtype(r->ttype), nilcheck = 1, stringtrick = 0;
-       BUN lcount = BATcount(l), rcount = BATcount(r);
-       lng t0 = GDKusec();
-
-       ALGODEBUG fprintf(stderr, "#BATproject(l=%s#" BUNFMT "%s%s%s,"
-                         "r=%s#" BUNFMT "[%s]%s%s%s)\n",
-                         BATgetId(l), BATcount(l),
-                         l->tsorted ? "-sorted" : "",
-                         l->trevsorted ? "-revsorted" : "",
-                         l->tkey & 1 ? "-key" : "",
-                         BATgetId(r), BATcount(r), ATOMname(r->ttype),
-                         r->tsorted ? "-sorted" : "",
-                         r->trevsorted ? "-revsorted" : "",
-                         r->tkey & 1 ? "-key" : "");
-
-       assert(BAThdense(l));
-       assert(BAThdense(r));
-       assert(ATOMtype(l->ttype) == TYPE_oid);
-
-       if (BATtdense(l) && BATcount(l) > 0) {
-               lo = l->tseqbase;
-               hi = l->tseqbase + BATcount(l);
-               if (lo < r->hseqbase || hi > r->hseqbase + BATcount(r)) {
-                       GDKerror("BATproject: does not match always\n");
-                       return NULL;
-               }
-               bn = BATslice(r, lo - r->hseqbase, hi - r->hseqbase);
-               if (bn == NULL)
-                       return NULL;
-               BATseqbase(bn, l->hseqbase + (lo - l->tseqbase));
-               ALGODEBUG fprintf(stderr, 
"#BATproject(l=%s,r=%s)=%s#"BUNFMT"%s%s%s\n",
-                                 BATgetId(l), BATgetId(r), BATgetId(bn), 
BATcount(bn),
-                                 bn->tsorted ? "-sorted" : "",
-                                 bn->trevsorted ? "-revsorted" : "",
-                                 bn->tkey & 1 ? "-key" : "");
-               assert(bn->htype == TYPE_void);
-               return bn;
-       }
-       if (l->ttype == TYPE_void || BATcount(l) == 0 ||
-           (r->ttype == TYPE_void && r->tseqbase == oid_nil)) {
-               /* trivial: all values are nil */
-               const void *nil = ATOMnilptr(r->ttype);
-
-               bn = BATconstant(r->ttype == TYPE_oid ? TYPE_void : r->ttype,
-                                nil, BATcount(l), TRANSIENT);
-               if (bn == NULL)
-                       return NULL;
-               BATseqbase(bn, l->hseqbase);
-               if (ATOMtype(bn->ttype) == TYPE_oid &&
-                   BATcount(bn) == 0) {
-                       bn->tdense = 1;
-                       BATseqbase(BATmirror(bn), 0);
-               }
-               ALGODEBUG fprintf(stderr, 
"#BATproject(l=%s,r=%s)=%s#"BUNFMT"%s%s%s\n",
-                                 BATgetId(l), BATgetId(r),
-                                 BATgetId(bn), BATcount(bn),
-                                 bn->tsorted ? "-sorted" : "",
-                                 bn->trevsorted ? "-revsorted" : "",
-                                 bn->tkey & 1 ? "-key" : "");
-               return bn;
-       }
-       assert(l->ttype == TYPE_oid);
-
-       if (ATOMstorage(tpe) == TYPE_str &&
-           l->T->nonil &&
-           (rcount == 0 ||
-            lcount > (rcount >> 3) ||
-            r->batRestricted == BAT_READ)) {
-               /* insert strings as ints, we need to copy the string
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to