Changeset: 00b70b43b071 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=00b70b43b071
Modified Files:
        sql/backends/monet5/LSST/Tests/lsst_htmxmatch.stable.out
        sql/backends/monet5/LSST/lsst.c
        sql/backends/monet5/LSST/lsst.h
        sql/backends/monet5/LSST/lsst.mal
Branch: default
Log Message:

Implemented missing parts and fixed existing parts of lsst.xmatch.


diffs (277 lines):

diff --git a/sql/backends/monet5/LSST/Tests/lsst_htmxmatch.stable.out 
b/sql/backends/monet5/LSST/Tests/lsst_htmxmatch.stable.out
--- a/sql/backends/monet5/LSST/Tests/lsst_htmxmatch.stable.out
+++ b/sql/backends/monet5/LSST/Tests/lsst_htmxmatch.stable.out
@@ -40,7 +40,22 @@ Ready.
 % bigint,      bigint # type
 % 3,   3 # length
 [ 100, 100     ]
-#select  * from htm a, htm b where a.id xmatch(1) b.id;
+[ 101, 101     ]
+[ 102, 102     ]
+[ 103, 103     ]
+[ 110, 110     ]
+[ 111, 111     ]
+[ 112, 112     ]
+[ 113, 113     ]
+[ 120, 120     ]
+[ 121, 121     ]
+[ 122, 122     ]
+[ 123, 123     ]
+[ 130, 130     ]
+[ 131, 131     ]
+[ 132, 132     ]
+[ 133, 133     ]
+#select  * from htm a, htm b where [a.id] xmatch [b.id,1];
 % sys.a,       sys.b # table_name
 % id,  id # name
 % bigint,      bigint # type
@@ -49,6 +64,50 @@ Ready.
 [ 100, 101     ]
 [ 100, 102     ]
 [ 100, 103     ]
+[ 101, 100     ]
+[ 101, 101     ]
+[ 101, 102     ]
+[ 101, 103     ]
+[ 102, 100     ]
+[ 102, 101     ]
+[ 102, 102     ]
+[ 102, 103     ]
+[ 103, 100     ]
+[ 103, 101     ]
+[ 103, 102     ]
+[ 103, 103     ]
+[ 110, 110     ]
+[ 110, 111     ]
+[ 111, 110     ]
+[ 111, 111     ]
+[ 112, 112     ]
+[ 112, 113     ]
+[ 113, 112     ]
+[ 113, 113     ]
+[ 120, 120     ]
+[ 120, 121     ]
+[ 120, 122     ]
+[ 120, 123     ]
+[ 121, 120     ]
+[ 121, 121     ]
+[ 121, 122     ]
+[ 121, 123     ]
+[ 122, 120     ]
+[ 122, 121     ]
+[ 122, 122     ]
+[ 122, 123     ]
+[ 123, 120     ]
+[ 123, 121     ]
+[ 123, 122     ]
+[ 123, 123     ]
+[ 130, 130     ]
+[ 130, 131     ]
+[ 131, 130     ]
+[ 131, 131     ]
+[ 132, 132     ]
+[ 132, 133     ]
+[ 133, 132     ]
+[ 133, 133     ]
 #drop table htm;
 
 # 21:23:59 >  
diff --git a/sql/backends/monet5/LSST/lsst.c b/sql/backends/monet5/LSST/lsst.c
--- a/sql/backends/monet5/LSST/lsst.c
+++ b/sql/backends/monet5/LSST/lsst.c
@@ -451,7 +451,7 @@ LSSTxmatch_intern(bat *lres, bat *rres, 
        lng lhtm, rhtm;
        lng *lend, *rend;
        int shift;
-       oid lo = 0, ro=0;
+       oid lo, ro;
 
        if( *delta < 0 || *delta >31)
                throw(MAL, "algebra.xmatch", "delta not in 0--31");
@@ -476,7 +476,6 @@ LSSTxmatch_intern(bat *lres, bat *rres, 
 
        l= (lng*) Tloc(bl, BUNfirst(bl));
        lend= (lng*) Tloc(bl, BUNlast(bl));
-       r= (lng*) Tloc(br, BUNfirst(br));
        rend= (lng*) Tloc(br, BUNlast(br));
 
        xl = BATnew(TYPE_void, TYPE_oid, MIN(BATcount(bl), BATcount(br)), 
TRANSIENT);
@@ -506,26 +505,34 @@ LSSTxmatch_intern(bat *lres, bat *rres, 
        xr->T->nonil = 1;
        xr->H->nonil = 1;
 
-       for(; l < lend; lo++, l++) 
-               if ( *l != lng_nil) {
+       for (lo = xl->hseqbase; l < lend; lo++, l++) {
+               if (*l != lng_nil) {
                        lhtm = *l >> shift;
-        for(; r < rend; ro++, r++)
-               if ( *r != lng_nil) {
-                       rhtm = *r >> shift;
-                       if ( lhtm == rhtm){
-                               /* match */
-                               BUNappend(xl,&lo, FALSE);
-                               BUNappend(xr,&ro, FALSE);
-                       } else if ( lhtm < rhtm ) {
-                               lhtm = lhtm << shift;
-                               for ( ; *l < lhtm && l < lend; lo++, l++)
-                                               ;
-                               lhtm = lhtm >> shift;
-                       } else {
-                               rhtm = rhtm << shift;
-                               for ( ; *r < rhtm && r < rend; ro++, r++)
-                                       ;
-                               rhtm = rhtm >> shift;
+                       r= (lng*) Tloc(br, BUNfirst(br));
+                       ro = br->hseqbase;
+                       for(; r < rend; ro++, r++) {
+                               if (*r != lng_nil) {
+                                       rhtm = *r >> shift;
+                                       if (lhtm == rhtm){
+                                               /* match */
+                                               BUNappend(xl, &lo, FALSE);
+                                               BUNappend(xr, &ro, FALSE);
+                                       } else if (lhtm < rhtm) {
+                                               lhtm = lhtm << shift;
+                                               while (*l < lhtm && l < lend) {
+                                                       lo++;
+                                                       l++;
+                                               }
+                                               lhtm = lhtm >> shift;
+                                       } else {
+                                               rhtm = rhtm << shift;
+                                               while (*r < rhtm && r < rend) {
+                                                       ro++;
+                                                       r++;
+                                               }
+                                               rhtm = rhtm >> shift;
+                                       }
+                               }
                        }
                }
        }
@@ -545,3 +552,93 @@ LSSTxmatchsubjoin(bat *lres, bat *rres, 
        (void)estimate;
        return LSSTxmatch_intern(lres, rres, lid, rid, delta);
 }
+
+str
+LSSTxmatch(bit *res, lng *l, lng *r, int *delta)
+{
+       int shift;
+
+       if (*delta < 0 || *delta > 31)
+               throw(MAL, "lsst.xmatch", "delta not in 0--31");
+       shift = 2 * *delta;
+
+       *res = *l != lng_nil && *r != lng_nil && (*l >> shift) == (*r >> shift);
+       return MAL_SUCCEED;
+}
+
+str
+LSSTxmatchsubselect(bat *res, bat *bid, bat *sid, lng *r, int *delta, bit 
*anti)
+{
+       int shift;
+       BAT *b, *s = NULL, *bn;
+       const lng *l;
+       lng lhtm, rhtm;
+
+       if (*delta < 0 || *delta > 31)
+               throw(MAL, "lsst.xmatch", "delta not in 0--31");
+       shift = 2 * *delta;
+
+       if ((b = BATdescriptor(*bid)) == NULL)
+               throw(MAL, "algebra.xmatch", RUNTIME_OBJECT_MISSING);
+       assert(b->ttype == TYPE_lng);
+       assert(BAThdense(b));
+       if (sid && *sid && (s = BATdescriptor(*sid)) == NULL) {
+               BBPunfix(b->batCacheid);
+               throw(MAL, "algebra.xmatch", RUNTIME_OBJECT_MISSING);
+       }
+       if ((bn = BATnew(TYPE_void, TYPE_oid, 0, TRANSIENT)) == NULL) {
+               BBPunfix(b->batCacheid);
+               if (s)
+                       BBPunfix(s->batCacheid);
+               throw(MAL, "algebra.xmatch", MAL_MALLOC_FAIL);
+       }
+       BATseqbase(bn, 0);
+       if (*r == lng_nil) {
+               BBPunfix(b->batCacheid);
+               if (s)
+                       BBPunfix(s->batCacheid);
+               BBPkeepref(*res = bn->batCacheid);
+               return MAL_SUCCEED;
+       }
+       rhtm = *r >> shift;
+       l = (const lng *) Tloc(b, BUNfirst(b));
+       if (s && !BATtdense(s)) {
+               const oid *sval = (const oid *) Tloc(s, BUNfirst(s));
+               oid o;
+               BUN i, scnt = BATcount(s);
+
+               for (i = 0; i < scnt && sval[i] < b->hseqbase; i++)
+                       ;
+               for (; i < scnt; i++) {
+                       o = sval[i];
+                       if (o >= b->hseqbase + BATcount(b))
+                               break;
+                       lhtm = l[o - b->hseqbase];
+                       if (lhtm != lng_nil)
+                               if (((lhtm >> shift) == rhtm) != *anti)
+                                       BUNappend(bn, &o, FALSE);
+               }
+       } else {
+               oid o = b->hseqbase;
+               oid e = o + BATcount(b);
+
+               if (s) {
+                       if (s->tseqbase > o)
+                               o = s->tseqbase;
+                       if (s->tseqbase + BATcount(s) < e)
+                               e = s->tseqbase + BATcount(s);
+               }
+               while (o < e) {
+                       lhtm = l[o - b->hseqbase];
+                       if (lhtm != lng_nil)
+                               if (((lhtm >> shift) == rhtm) != *anti)
+                                       BUNappend(bn, &o, FALSE);
+                       o++;
+               }
+       }
+       BBPunfix(b->batCacheid);
+       if (s)
+               BBPunfix(s->batCacheid);
+       BBPkeepref(*res = bn->batCacheid);
+       return MAL_SUCCEED;
+}
diff --git a/sql/backends/monet5/LSST/lsst.h b/sql/backends/monet5/LSST/lsst.h
--- a/sql/backends/monet5/LSST/lsst.h
+++ b/sql/backends/monet5/LSST/lsst.h
@@ -40,6 +40,8 @@ lsst_export str qserv_ptInSphEllipse(int
 lsst_export str qserv_ptInSphCircle(int *ret, dbl *ra, dbl *dec, dbl *ra_cen, 
dbl *dec_cen, dbl *radius);
 lsst_export str qserv_ptInSphPoly(Client cntxt, MalBlkPtr mb, MalStkPtr stk, 
InstrPtr pci);
 
+lsst_export str LSSTxmatch(bit *res, lng *l, lng *r, int *delta);
+lsst_export str LSSTxmatchsubselect(bat *res, bat *bid, bat *sid, lng *r, int 
*depth, bit *anti);
 lsst_export str LSSTxmatchsubjoin(bat *l, bat *r, bat *lid, bat *rid, int 
*delta, bat *sl, bat *sr, bit *nil_matches, lng *estimate);
 
 #endif /* _SQL_LSST_H_ */
diff --git a/sql/backends/monet5/LSST/lsst.mal 
b/sql/backends/monet5/LSST/lsst.mal
--- a/sql/backends/monet5/LSST/lsst.mal
+++ b/sql/backends/monet5/LSST/lsst.mal
@@ -38,14 +38,10 @@ pattern lsst.ptinsphpoly(ra:dbl, dec:dbl
 address qserv_ptInSphPoly
 comment "Returns 1 if the given spherical longitude/latitude polyline contains 
the given position";
 
-command lsst.xmatch(l:lng, r:lng, depth:int, anti:bit) :bit
+command lsst.xmatch(l:lng, r:lng, depth:int) :bit
 address LSSTxmatch
 comment "Return true when the HtmID pairs that lie within the same triangle at 
level depth";
 
-command lsst.xmatch(l:bat[:oid,:lng], r:bat[:oid,:lng], depth:int, anti:bit) 
:bit
-address LSSTxmatch
-comment "Return the HtmID pairs that lie within the same triangle at level 
depth";
-
 command lsst.xmatchsubselect(l:bat[:oid,:lng], cand:bat[:oid,:oid], r:lng, 
depth:int, anti:bit):bat[:oid,:oid]
 address LSSTxmatchsubselect
 comment "Return the HtmID's that lie within the same triangle as r at level 
depth";
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to