Changeset: f2162c97d88f for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=f2162c97d88f Added Files: monetdb5/modules/mal/Tests/pqueue2.mal Modified Files: monetdb5/modules/mal/pqueue.c monetdb5/modules/mal/pqueue.h monetdb5/modules/mal/pqueue.mal Branch: default Log Message:
prepare next step of pqueue upgrade Awaiting proper micro tests diffs (truncated from 400 to 300 lines): diff --git a/monetdb5/modules/mal/Tests/pqueue2.mal b/monetdb5/modules/mal/Tests/pqueue2.mal new file mode 100644 --- /dev/null +++ b/monetdb5/modules/mal/Tests/pqueue2.mal @@ -0,0 +1,63 @@ +# enqueue something +a:= bat.new(:oid,:oid); + +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); + +io.print(a); + +b:= bat.new(:oid,:int); + +bat.append(b,1); +bat.append(b,0); +bat.append(b,2); +bat.append(b,2); +bat.append(b,5); +bat.append(b,5); +bat.append(b,3); + +io.print(b); + +bp:= pqueue.topn_min(a,b,0:wrd,false); +io.print(bp); +bp:= pqueue.topn_min(a,b,1:wrd,false); +io.print(bp); +bp:= pqueue.topn_min(a,b,2:wrd,false); +io.print(bp); +bp:= pqueue.topn_min(a,b,3:wrd,false); +io.print(bp); +bp:= pqueue.topn_min(a,b,4:wrd,false); +io.print(bp); +bp:= pqueue.topn_min(a,b,5:wrd,false); +io.print(bp); +bp:= pqueue.topn_min(a,b,6:wrd,false); +io.print(bp); +bp:= pqueue.topn_min(a,b,7:wrd,false); +io.print(bp); +bp:= pqueue.topn_min(a,b,8:wrd,false); +io.print(bp); + +bp:= pqueue.topn_max(a,b,0:wrd,false); +io.print(bp); +bp:= pqueue.topn_max(a,b,1:wrd,false); +io.print(bp); +bp:= pqueue.topn_max(a,b,2:wrd,false); +io.print(bp); +bp:= pqueue.topn_max(a,b,3:wrd,false); +io.print(bp); +bp:= pqueue.topn_max(a,b,4:wrd,false); +io.print(bp); +bp:= pqueue.topn_max(a,b,5:wrd,false); +io.print(bp); +bp:= pqueue.topn_max(a,b,6:wrd,false); +io.print(bp); +bp:= pqueue.topn_max(a,b,7:wrd,false); +io.print(bp); +bp:= pqueue.topn_max(a,b,8:wrd,false); +io.print(bp); + 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 @@ -1409,7 +1409,7 @@ PQtopreplace_anymax(Client cntxt, MalBlk } /* some new code for headless */ -#define QTOPN_shuffle(TYPE,OPER)\ +#define QTOPN_shuffle(TYPE,OPER,LAB)\ { TYPE *val = (TYPE *) Tloc(b,BUNfirst(b)), v;\ for(o = 0; o < lim; o++){\ v = val[o];\ @@ -1422,20 +1422,21 @@ PQtopreplace_anymax(Client cntxt, MalBlk oo = tmp;\ } else \ if (elimdup && (TYPE) val[o] == (TYPE) val[idx[i]])\ - goto skipit##TYPE;\ + goto skipit##TYPE##LAB;\ if( top < size)\ idx[top++] = oo;\ - skipit##TYPE:;\ + skipit##TYPE##LAB:;\ }\ } -str PQtopn_min(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) +str PQtopn_minmax(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) { int tpe, *ret; int elimdup; BAT *b,*bn; BUN i, size,top = 0; oid *idx, lim, o, oo, tmp; + int max = 0; (void) cntxt; ret = (int*) getArgReference(stk, pci, 0); @@ -1443,6 +1444,7 @@ str PQtopn_min(Client cntxt, MalBlkPtr m size = (BUN) *(wrd*) getArgReference(stk,pci,2); elimdup = *(bit*) getArgReference(stk,pci,3); + max = strstr(getFunctionId(pci),"max") != 0; b = BATdescriptor(*(bat *) getArgReference(stk, pci, 1)); if (!b) throw(MAL, "topn_min", RUNTIME_OBJECT_MISSING); @@ -1461,38 +1463,70 @@ str PQtopn_min(Client cntxt, MalBlkPtr m if (!bn){ BBPreleaseref(b->batCacheid); - throw(MAL, "topn_min", RUNTIME_OBJECT_MISSING); + throw(MAL, getFunctionId(pci), RUNTIME_OBJECT_MISSING); } // shuffle insert new values, keep it simple! - if( size) - switch(tpe){ - case TYPE_bte: QTOPN_shuffle(bte,<) break; - case TYPE_sht: QTOPN_shuffle(sht,<) break; - case TYPE_int: QTOPN_shuffle(int,<) break; - case TYPE_wrd: QTOPN_shuffle(wrd,<) break; - case TYPE_lng: QTOPN_shuffle(lng,<) break; - case TYPE_flt: QTOPN_shuffle(flt,<) break; - case TYPE_dbl: QTOPN_shuffle(dbl,<) break; - default: - { void *v; - int k; - for(o = 0; o < lim; o++){ - v = (void*) Tloc(b,o); - oo = o; - for (i= 0; i<top; i++) - if ( (k = atom_CMP( v, Tloc(b,idx[i]), tpe)) < 0) { - v = Tloc(b,idx[i]); - tmp = idx[i]; - idx[i]= oo; - oo = tmp; - } else - if (elimdup && k == 0) - goto skipitdefault; - if( top < size) - idx[top++] = oo; - skipitdefault:; + if( size){ + if ( max ) + switch(tpe){ + case TYPE_bte: QTOPN_shuffle(bte,>,GTR) break; + case TYPE_sht: QTOPN_shuffle(sht,>,GTR) break; + case TYPE_int: QTOPN_shuffle(int,>,GTR) break; + case TYPE_wrd: QTOPN_shuffle(wrd,>,GTR) break; + case TYPE_lng: QTOPN_shuffle(lng,>,GTR) break; + case TYPE_flt: QTOPN_shuffle(flt,>,GTR) break; + case TYPE_dbl: QTOPN_shuffle(dbl,>,GTR) break; + default: + { void *v; + int k; + for(o = 0; o < lim; o++){ + v = (void*) Tloc(b,o); + oo = o; + for (i= 0; i<top; i++) + if ( (k = atom_CMP( v, Tloc(b,idx[i]), tpe)) > 0) { + v = Tloc(b,idx[i]); + tmp = idx[i]; + idx[i]= oo; + oo = tmp; + } else + if (elimdup && k == 0) + goto skipitdefaultGTR; + if( top < size) + idx[top++] = oo; + skipitdefaultGTR:; + } } - } + } + if ( max == 0 ) + switch(tpe){ + case TYPE_bte: QTOPN_shuffle(bte,<,LESS) break; + case TYPE_sht: QTOPN_shuffle(sht,<,LESS) break; + case TYPE_int: QTOPN_shuffle(int,<,LESS) break; + case TYPE_wrd: QTOPN_shuffle(wrd,<,LESS) break; + case TYPE_lng: QTOPN_shuffle(lng,<,LESS) break; + case TYPE_flt: QTOPN_shuffle(flt,<,LESS) break; + case TYPE_dbl: QTOPN_shuffle(dbl,<,LESS) break; + default: + { void *v; + int k; + for(o = 0; o < lim; o++){ + v = (void*) Tloc(b,o); + oo = o; + for (i= 0; i<top; i++) + if ( (k = atom_CMP( v, Tloc(b,idx[i]), tpe)) < 0) { + v = Tloc(b,idx[i]); + tmp = idx[i]; + idx[i]= oo; + oo = tmp; + } else + if (elimdup && k == 0) + goto skipitdefault; + if( top < size) + idx[top++] = oo; + skipitdefault:; + } + } + } } BATsetcount(bn, (BUN) top); @@ -1503,70 +1537,102 @@ str PQtopn_min(Client cntxt, MalBlkPtr m return MAL_SUCCEED; } -str PQtopn_max(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) +str PQtopn2_minmax(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) { int tpe, *ret; int elimdup; - BAT *b,*bn; + BAT *a, *b,*bn; BUN i, size,top = 0; oid *idx, lim, o, oo, tmp; + int max = 0; (void) cntxt; ret = (int*) getArgReference(stk, pci, 0); - tpe = ATOMstorage(getColumnType(getArgType(mb, pci, 1))); - size = (BUN) *(wrd*) getArgReference(stk,pci,2); - elimdup = *(bit*) getArgReference(stk,pci,3); + tpe = ATOMstorage(getColumnType(getArgType(mb, pci, 2))); + size = (BUN) *(wrd*) getArgReference(stk,pci,3); + elimdup = *(bit*) getArgReference(stk,pci,4); - b = BATdescriptor(*(bat *) getArgReference(stk, pci, 1)); - if (!b) + max = strstr(getFunctionId(pci),"max") != 0; + a = BATdescriptor(*(bat *) getArgReference(stk, pci, 1)); + if (!a) throw(MAL, "topn_min", RUNTIME_OBJECT_MISSING); + b = BATdescriptor(*(bat *) getArgReference(stk, pci, 2)); + if (!b){ + BBPreleaseref(a->batCacheid); + throw(MAL, "topn_min", RUNTIME_OBJECT_MISSING); + } lim = BATcount(b); - if( b->tsorted){ - bn = BATslice(b, BATcount(b) < size? BATcount(b):0, size); - BBPkeepref(*ret = bn->batCacheid); - BBPreleaseref(b->batCacheid); - return MAL_SUCCEED; - } - bn = BATnew(TYPE_void, TYPE_oid, size+1); BATseqbase(bn,0); idx = (oid*) Tloc(bn,BUNfirst(bn)); if (!bn){ BBPreleaseref(b->batCacheid); - throw(MAL, "topn_min", RUNTIME_OBJECT_MISSING); + throw(MAL, getFunctionId(pci), RUNTIME_OBJECT_MISSING); } // shuffle insert new values, keep it simple! - if( size) - switch(tpe){ - case TYPE_bte: QTOPN_shuffle(bte,>) break; - case TYPE_sht: QTOPN_shuffle(sht,>) break; - case TYPE_int: QTOPN_shuffle(int,>) break; - case TYPE_wrd: QTOPN_shuffle(wrd,>) break; - case TYPE_lng: QTOPN_shuffle(lng,>) break; - case TYPE_flt: QTOPN_shuffle(flt,>) break; - case TYPE_dbl: QTOPN_shuffle(dbl,>) break; - default: - { void *v; - int k; - for(o = 0; o < lim; o++){ - v = (void*) Tloc(b,o); - oo = o; - for (i= 0; i<top; i++) - if ( (k = atom_CMP( v, Tloc(b,idx[i]), tpe)) > 0) { - v = Tloc(b,idx[i]); - tmp = idx[i]; - idx[i]= oo; - oo = tmp; - } else - if (elimdup && k == 0) - goto skipitdefault; - if( top < size) - idx[top++] = oo; - skipitdefault:; + if( size){ + if ( max ==0) + switch(tpe){ + case TYPE_bte: QTOPN_shuffle(bte,>,GTR) break; + case TYPE_sht: QTOPN_shuffle(sht,>,GTR) break; + case TYPE_int: QTOPN_shuffle(int,>,GTR) break; _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list