Changeset: 1ae40a464451 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=1ae40a464451
Modified Files:
        monetdb5/modules/mal/Tests/pqueue2.mal
        monetdb5/modules/mal/pqueue.c
        monetdb5/modules/mal/pqueue.h
        monetdb5/modules/mal/pqueue.mal
Branch: default
Log Message:

Another round for new interface of pqueue


diffs (truncated from 536 to 300 lines):

diff --git a/monetdb5/modules/mal/Tests/pqueue2.mal 
b/monetdb5/modules/mal/Tests/pqueue2.mal
--- a/monetdb5/modules/mal/Tests/pqueue2.mal
+++ b/monetdb5/modules/mal/Tests/pqueue2.mal
@@ -1,13 +1,13 @@
 # enqueue something 
-a:= bat.new(:oid,:oid);
+a:= bat.new(:oid,:int);
 
-bat.append(a,1@0);
-bat.append(a,0@0);
-bat.append(a,2@0);
-bat.append(a,2@0);
-bat.append(a,3@0);
-bat.append(a,3@0);
-bat.append(a,3@0);
+bat.append(a,1);
+bat.append(a,0);
+bat.append(a,2);
+bat.append(a,2);
+bat.append(a,3);
+bat.append(a,3);
+bat.append(a,3);
 
 io.print(a);
 
@@ -64,75 +64,65 @@ io.print("Start of compound");
 (bp,bg):= pqueue.topn_min(b,0:wrd);
 io.print(bp);
 io.print(bg);
-ap := algebra.leftfetchjoin(bp, a);
-io.print(ap);
 # (sub) topn input: aligned bg group id, ap values bat
 #      output: void,pos
 # returns the topn of the combination gid,value
-bp:= pqueue.topn_min(bg,ap,0:wrd);
-io.print(bp);
+(cp,cg):= pqueue.topn_min(a,bp,bg,0:wrd);
+io.print(cp);
 
 (bp,bg):= pqueue.topn_min(b,1:wrd);
 io.print(bp);
 io.print(bg);
-ap := algebra.leftfetchjoin(bp, a);
-io.print(ap);
-bp:= pqueue.topn_min(bg,ap,1:wrd);
-io.print(bp);
+(cp,cg):= pqueue.topn_min(a,bp,bg,1:wrd);
+io.print(cp);
+io.print(cg);
 
 (bp,bg):= pqueue.topn_min(b,2:wrd);
 io.print(bp);
 io.print(bg);
-ap := algebra.leftfetchjoin(bp, a);
-io.print(ap);
-bp:= pqueue.topn_min(bg,ap,2:wrd);
-io.print(bp);
+(cp,cg):= pqueue.topn_min(a,bp,bg,2:wrd);
+io.print(cp);
+io.print(cg);
 
 (bp,bg):= pqueue.topn_min(b,3:wrd);
 io.print(bp);
 io.print(bg);
-ap := algebra.leftfetchjoin(bp, a);
-io.print(ap);
-bp:= pqueue.topn_min(bg,ap,3:wrd);
-io.print(bp);
+(cp,cg):= pqueue.topn_min(a,bp,bg,3:wrd);
+io.print(cp);
+io.print(cg);
 
 (bp,bg):= pqueue.topn_min(b,4:wrd);
 io.print(bp);
 io.print(bg);
-ap := algebra.leftfetchjoin(bp, a);
-io.print(ap);
-bp:= pqueue.topn_min(bg,ap,4:wrd);
-io.print(bp);
+(cp,cg):= pqueue.topn_min(a,bp,bg,4:wrd);
+io.print(cp);
+io.print(cg);
 
 (bp,bg):= pqueue.topn_min(b,5:wrd);
 io.print(bp);
 io.print(bg);
-ap := algebra.leftfetchjoin(bp, a);
-io.print(ap);
-bp:= pqueue.topn_min(bg,ap,5:wrd);
-io.print(bp);
+(cp,cg):= pqueue.topn_min(a,bp,bg,5:wrd);
+io.print(cp);
+io.print(cg);
 
 (bp,bg):= pqueue.topn_min(b,6:wrd);
 io.print(bp);
 io.print(bg);
-ap := algebra.leftfetchjoin(bp, a);
-io.print(ap);
-bp:= pqueue.topn_min(bg,ap,6:wrd);
-io.print(bp);
+(cp,cg):= pqueue.topn_min(a,bp,bg,6:wrd);
+io.print(cp);
+io.print(cg);
 
 (bp,bg):= pqueue.topn_min(b,7:wrd);
 io.print(bp);
 io.print(bg);
-ap := algebra.leftfetchjoin(bp, a);
-io.print(ap);
-bp:= pqueue.topn_min(bg,ap,7:wrd);
-io.print(bp);
+(cp,cg):= pqueue.topn_min(a,bp,bg,7:wrd);
+io.print(cp);
+io.print(cg);
 
 (bp,bg):= pqueue.topn_min(b,8:wrd);
 io.print(bp);
 io.print(bg);
-ap := algebra.leftfetchjoin(bp, a);
-io.print(ap);
-bp:= pqueue.topn_min(bg,ap,8:wrd);
-io.print(bp);
+(cp,cg):= pqueue.topn_min(a,bp,bg,8:wrd);
+io.print(cp);
+io.print(cg);
 
diff --git a/monetdb5/modules/mal/pqueue.c b/monetdb5/modules/mal/pqueue.c
--- a/monetdb5/modules/mal/pqueue.c
+++ b/monetdb5/modules/mal/pqueue.c
@@ -1669,24 +1669,26 @@ str PQtopn2_minmax(Client cntxt, MalBlkP
 
 /* some new code for headless */
 #define QTOPN_shuffle3(TYPE,OPER)\
-{      TYPE *val = (TYPE *) Tloc(bpiv,BUNfirst(bpiv));\
+{      TYPE *val = (TYPE *) Tloc(a,BUNfirst(a));\
        uniq = 0;\
        gid = BUN_MAX;\
-       for(o = 0; top < size && o < lim; o++){\
-               idx[top] = gdx[o];\
-               if ( gdx[top] != gid){\
-                       gid = gdx[o];\
-                       if( uniq < size) top++;\
+       for(o = 0; uniq <= size && o < lim; o++){\
+               cpx[top] = bpx[o];\
+               cgx[top] = bgx[o];\
+               if ( cgx[top] != gid){\
+                       gid = cgx[o];\
+                       top++;\
                        uniq++;\
                        continue;\
                }\
-               if(uniq >= size &&  (TYPE) val[o] OPER##= (TYPE) 
val[idx[top-1]]) \
+               if(uniq >= size &&  (TYPE) val[cpx[o]] OPER##= (TYPE) 
val[cpx[top-1]]) \
                        continue;\
                for (i= top; i>0; i--){\
-                       if ( gdx[i-1] != gid)\
+                       if ( cgx[i-1] != gid)\
                                break;\
-                       if( (TYPE) val[idx[i]] OPER (TYPE) val[idx[i-1]]){\
-                               tmp= idx[i]; idx[i] = idx[i-1]; idx[i-1] = tmp;\
+                       if( (TYPE) val[cpx[i]] OPER (TYPE) val[cpx[i-1]]){\
+                               tmp= cpx[i]; cpx[i] = cpx[i-1]; cpx[i-1] = tmp;\
+                               tmp= cgx[i]; cgx[i] = cgx[i-1]; cgx[i-1] = tmp;\
                        } else\
                                break;\
                }\
@@ -1697,43 +1699,62 @@ str PQtopn2_minmax(Client cntxt, MalBlkP
 str PQtopn3_minmax(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
 {
        
-       int tpe, *ret;
-       BAT *bn,*bpiv, *bgid;
+       int tpe, *retcp,*retcg;
+       BAT *bp,*bg, *a, *cp, *cg;
        BUN i, size, top = 0, uniq, gid;
-       oid *idx, *gdx, lim, o, tmp;
+       oid *bpx, *bgx, *cpx, *cgx, lim, o, tmp;
        int k,max = 0;
 
        (void) cntxt;
-       ret = (int*) getArgReference(stk, pci, 0);
+       (void) k;
+       retcp = (int*) getArgReference(stk, pci, 0);
+       retcg = (int*) getArgReference(stk, pci, 1);
        tpe = ATOMstorage(getColumnType(getArgType(mb, pci, 2)));
-       size = (BUN) *(wrd*) getArgReference(stk,pci,3);
+       size = (BUN) *(wrd*) getArgReference(stk,pci,5);
        max = strstr(getFunctionId(pci),"max") != 0;
 
-       bgid = BATdescriptor(*(bat *) getArgReference(stk, pci, 1));
-       if (!bgid)
+       a = BATdescriptor(*(bat *) getArgReference(stk, pci, 2));
+       if (!a)
                throw(MAL, "topn_min", RUNTIME_OBJECT_MISSING);
 
-       bpiv = BATdescriptor(*(bat *) getArgReference(stk, pci, 2));
-       if (!bpiv){
-               BBPreleaseref(bgid->batCacheid);
+       bp = BATdescriptor(*(bat *) getArgReference(stk, pci, 3));
+       if (!bp){
+               BBPreleaseref(a->batCacheid);
                throw(MAL, "topn_min", RUNTIME_OBJECT_MISSING);
        }
-       if( BATcount(bpiv) != BATcount(bgid)){
-               BBPreleaseref(bgid->batCacheid);
-               BBPreleaseref(bpiv->batCacheid);
-               throw(MAL,"topn_minmax","Arguments not aligned");
+
+       bg = BATdescriptor(*(bat *) getArgReference(stk, pci, 4));
+       if (!bg){
+               BBPreleaseref(a->batCacheid);
+               BBPreleaseref(bp->batCacheid);
+               throw(MAL, "topn_min", RUNTIME_OBJECT_MISSING);
        }
 
-       bn = BATnew(TYPE_void, TYPE_oid, BATcount(bpiv));
-       if (!bn){
-               BBPreleaseref(bgid->batCacheid);
-               BBPreleaseref(bpiv->batCacheid);
-               throw(MAL, "topn_min", RUNTIME_OBJECT_MISSING);
+       cp = BATnew(TYPE_void, TYPE_oid, BATcount(bp));
+       if (!cp){
+               BBPreleaseref(a->batCacheid);
+               BBPreleaseref(bg->batCacheid);
+               BBPreleaseref(bp->batCacheid);
+               throw(MAL, "topn_min", MAL_MALLOC_FAIL);
        }
-       lim = BATcount(bpiv);
-       BATseqbase(bn,0);
-       idx = (oid*) Tloc(bn,BUNfirst(bpiv));
-       gdx = (oid*) Tloc(bgid,BUNfirst(bgid));
+       cg = BATnew(TYPE_void, TYPE_oid, BATcount(bp));
+       if (!cg){
+               BBPreleaseref(a->batCacheid);
+               BBPreleaseref(bg->batCacheid);
+               BBPreleaseref(bp->batCacheid);
+               BBPreleaseref(cp->batCacheid);
+               throw(MAL, "topn_min", MAL_MALLOC_FAIL);
+       }
+
+       lim = BATcount(bp);
+       BATseqbase(cp,0);
+       BATseqbase(cg,0);
+
+       bgx = (oid*) Tloc(bg,BUNfirst(bg));
+       bpx = (oid*) Tloc(bp,BUNfirst(bp));
+
+       cpx = (oid*) Tloc(cp,BUNfirst(cp));
+       cgx = (oid*) Tloc(cg,BUNfirst(cg));
 
        // shuffle insert new values, keep it simple!
        if( size){
@@ -1741,7 +1762,7 @@ str PQtopn3_minmax(Client cntxt, MalBlkP
                switch(tpe){
                case TYPE_bte: QTOPN_shuffle3(bte,<) break;
                case TYPE_sht: QTOPN_shuffle3(sht,<) break;
-               case TYPE_int: QTOPN_shuffle3(sht,<) break;
+               case TYPE_int: QTOPN_shuffle3(int,<) break;
                case TYPE_wrd: QTOPN_shuffle3(wrd,<) break;
                case TYPE_lng: QTOPN_shuffle3(lng,<) break;
                case TYPE_flt: QTOPN_shuffle3(flt,<) break;
@@ -1749,29 +1770,33 @@ str PQtopn3_minmax(Client cntxt, MalBlkP
                default:
                {       uniq = 0;
                        gid = BUN_MAX;
-                       for(o = 0; top<size && o < lim; o++){
-                               idx[top] = gdx[o];
-                               if ( gdx[top] != gid){
-                                       gid = gdx[o];
-                                       if( uniq <= size) top++;
+                       for(o = 0; uniq<=size && o < lim; o++){
+                               cpx[top] = bpx[o];
+                               cgx[top] = bgx[o];
+                               if ( cgx[top] != gid){
+                                       gid = cgx[o];\
+                                       top++;
                                        uniq++;
                                        continue;
                                }
-                               k = atom_CMP( Tloc(bpiv,o), 
Tloc(bpiv,idx[top-1]), tpe) >= 0;
+                               k = atom_CMP( Tloc(bp,cpx[o]), 
Tloc(bp,cpx[top-1]), tpe) <= 0;
                                if( uniq >= size &&  k) 
                                        continue;
                                for (i= top; i>0; i--){
-                                       if ( gdx[i-1] != gid)
+                                       if ( cgx[i-1] != gid)
                                                break;
-                                       if ( (k = atom_CMP( Tloc(bpiv,idx[i]), 
Tloc(bpiv,idx[i-1]), tpe)) < 0) {
-                                               tmp= idx[i]; idx[i] = idx[i-1]; 
idx[i-1] = tmp;
+                                       if ( (k = atom_CMP( Tloc(bp,cpx[i]), 
Tloc(bp,cpx[i-1]), tpe)) < 0) {
+                                               tmp= cpx[i]; cpx[i] = cpx[i-1]; 
cpx[i-1] = tmp;
+                                               tmp= cgx[i]; cgx[i] = cgx[i-1]; 
cgx[i-1] = tmp;
                                        } else
                                                break;
                                }
                                top++; 
                        }
                }
+
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to