📄 pbm.c
字号:
#line 272 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/pbm.mx"#include "mal_config.h"#include "pbm.h"PBAT partitions = NULL;int ptop=0, plimit=0;#define INCREMENT 1024voidPBMresize(int size){ PBAT p; if( size <= plimit) return; p = GDKmalloc(size * sizeof(PBATrecord)); memset((char*)p, 0, size * sizeof(PBATrecord)); if (partitions) { if (ptop > size) GDKfatal("assertion error in PBMresize"); memcpy(p, partitions, sizeof(PBATrecord) * ptop); GDKfree(partitions); } partitions = p; partitions[0].grp = NULL; partitions[0].elm = NULL; partitions[0].bid = -1; partitions[0].prev = -1; partitions[0].next = -1; plimit = size;}static voidPBMfreePartition(int i){ BAT *b; if( partitions[i].grp){ b= (BAT*) BBPgetdesc(partitions[i].bid); if( b== 0) GDKerror("inconsistent pbm, lost a BAT"); else{ b->batPersistence = TRANSIENT; BBPdecref(b->batCacheid,TRUE); BBPunfix(b->batCacheid); } } if( partitions[i].grp) GDKfree(partitions[i].grp); if( partitions[i].elm) GDKfree(partitions[i].elm); partitions[i].grp = NULL; partitions[i].elm = NULL; partitions[i].bid = -1; partitions[i].prev = -1; partitions[i].next = -1;}static voidPBMfree(){ int i; if (partitions) { for(i=0; i<plimit; i++){ if( partitions[i].grp) GDKfree(partitions[i].grp); if( partitions[i].elm) GDKfree(partitions[i].elm); } GDKfree(partitions); partitions = NULL; }}strPBMdump(){ stream *fd = GDKout; int i; stream_printf(fd, "ptop=%d plimit=%d\n", ptop, plimit); for (i = 0; i < ptop; i++){ stream_printf(fd, "[%d] grp=%s elm=%s bid=%d type=%d prv=%d nxt=%d\n", i, partitions[i].grp, partitions[i].elm, partitions[i].bid, partitions[i].type, partitions[i].prev, partitions[i].next); /* bounds for later */ } return MAL_SUCCEED;}#line 357 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/pbm.mx"strPBMprelude(int *ret){ Box box; (void) ret; box = openBox("partitions"); (void) box;/* if (box == 0) throw(MAL, "pbm.prelude", "failed to open box");*/ PBMresize(INCREMENT); return MAL_SUCCEED;}strPBMepilogue(int *ret){ *ret = closeBox("partitions", 0); PBMfree(); if (*ret != 0) throw(MAL, "pbm.prelude", "failed to open box"); return MAL_SUCCEED;}strPBMopen(int *ret){ (void)* ret; if (openBox("pbm") != 0) return MAL_SUCCEED; throw(MAL, "pbm.open", "failed to open pbm box");}strPBMclose(int *ret){ stream *f; str boxfile, boxfilebak; Box box; BAT *b; int i; (void)* ret; box = openBox("pbm"); f = prepareSaveBox(box, &boxfile, &boxfilebak); if (f != NULL) { /* save the info */ for (i = 0; i < ptop; i++) if (partitions[i].bid != -1) { b = (BAT *) BBPgetdesc(partitions[i].bid); if (b && b->batPersistence & PERSISTENT) stream_printf(f, "pbm.deposit(\"%s\",\"%s\",\"%s\");\n", partitions[i].grp, partitions[i].elm, BBPname(partitions[i].bid)); } stream_close(f); GDKfree(boxfile); GDKfree(boxfilebak); } return MAL_SUCCEED;}strPBMdestroy(int *ret){ (void)* ret; destroyBox("partitions"); return MAL_SUCCEED;}#line 435 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/pbm.mx"strPBMtakeComplete(int *ret, str *grp){ BAT *b,*bn; int i; i = PBMfindPBAT(*grp); if( i<0) throw(MAL, "pbm.take","PBAT not found"); b= BBPdescriptor(partitions[i].bid); if( b== NULL) throw(MAL, "pbm.take", "PBAT partition not accessible"); bn= BATcopy(b, b->htype, b->ttype, TRUE); BBPunfix(b->batCacheid); for(i= partitions[i].next; i>= 0; i= partitions[i].next){ b= BBPdescriptor(partitions[i].bid); if( b== NULL){ BBPdecref(bn->batCacheid, TRUE); BBPunfix(bn->batCacheid); throw(MAL, "pbm.take", "PBAT partition not accessible"); } BATins(bn,b,FALSE); BBPunfix(b->batCacheid); } *ret = bn->batCacheid; BBPkeepref(*ret); return MAL_SUCCEED;}strPBMtake(int *ret, str *grp, str *elm){ BAT *b; int i; for( i=0; i< plimit; i++) if( partitions[i].grp && strcmp(partitions[i].grp, *grp)== 0 && strcmp(partitions[i].elm, *elm)== 0) break; if( i== plimit ) throw(MAL, "pbm.take", "PBAT partition not found"); b= BBPdescriptor(partitions[i].bid); if( b== NULL) throw(MAL, "pbm.take", "PBAT partition not accessible"); *ret = partitions[i].bid; BBPkeepref(*ret); return MAL_SUCCEED;}strPBMtakeIndexed(int *ret, str *grp, int *idx){ BAT *b; int i; i= PBMfindPBAT(*grp); if( i< 0) throw(MAL, "pbm.take","PBAT not found"); for( ; i>=0 && *idx>0; i= partitions[i].next) *idx= *idx-1; if( i< 0) throw(MAL, "pbm.take","PBAT component not found"); b= BBPdescriptor(partitions[i].bid); if( b== NULL) throw(MAL, "pbm.take", "PBAT partition not accessible"); *ret = partitions[i].bid; BBPkeepref(*ret); return MAL_SUCCEED;}strPBMgetComponents(int *ret, str *grp){ BAT *b; int i; b= BATnew(TYPE_str,TYPE_str, oid_nil); if( b==NULL) throw(MAL, "pbm.getComponents", "Could not create BAT"); for( i= PBMfindPBAT(*grp); i>=0; i= partitions[i].next) BUNins(b,grp, partitions[i].elm, FALSE); if (!(b->batDirty&2)) b = BATsetaccess(b, BAT_READ); *ret = b->batCacheid; BBPkeepref(*ret); return MAL_SUCCEED;}strPBMgetNames(int *ret){ BAT *b; int i; b= BATnew(TYPE_str,TYPE_str, oid_nil); if( b==NULL) throw(MAL, "pbm.getNames", "Could not create BAT"); for( i= 0; i<ptop; i++) if( partitions[i].grp ) BUNins(b,partitions[i].grp, partitions[i].elm, FALSE); if (!(b->batDirty&2)) b = BATsetaccess(b, BAT_READ); *ret = b->batCacheid; BBPkeepref(*ret); return MAL_SUCCEED;}#line 536 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/pbm.mx"intPBMfindGrp(int bid){ int i; for (i = 0; i < ptop; i++) if (partitions[i].bid == bid) { while (partitions[i].prev >= 0) i = partitions[i].prev; return i; } return -1;}#line 553 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/pbm.mx"intPBMfindPBAT(str grp){ int i; for (i = 0; i < ptop; i++) if( partitions[i].grp && strcmp(partitions[i].grp,grp)==0 && partitions[i].prev == -1 ) return i; return -1;}intPBMfindPBATcomponent(str grp, str elm){ int i; for (i = 0; i < ptop; i++) if( strcmp(partitions[i].grp,grp)==0 && strcmp(partitions[i].elm,elm)== 0) return i; return -1;}strPBMdeposit(int *ret, str *grp, str *elm, int *bid){ int idx, i,j; BAT *b; if( elm){ i= PBMfindPBATcomponent(*grp,*elm); if( i >=0 ) throw(MAL, "pbm.deposit", "PBAT component already known"); } b = BATdescriptor(*bid); if (b == NULL) throw(MAL, "pbm.deposit", "Can not access descriptor"); idx = PBMfindPBAT(*grp); if (ptop == plimit) PBMresize(plimit + INCREMENT); for (i = 0; i <= ptop; i++) if (partitions[i].bid == -1) break; partitions[i].grp = GDKstrdup(*grp); partitions[i].elm = elm?GDKstrdup(*elm):0; partitions[i].bid = *bid; partitions[i].type = newBatType(b->htype, b->ttype); partitions[i].hmin.val.oval = b->hseqbase; partitions[i].hmax.val.oval = b->hseqbase + BATcount(b); partitions[i].prev = -1; partitions[i].next = -1; if (i >= ptop) { ptop = i + 1; partitions[ptop].bid = -1; partitions[ptop].next = -1; partitions[ptop].prev = -1; } if( idx >=0){ for(j=idx; partitions[j].next>=0; j= partitions[j].next) ; partitions[j].next = i; partitions[i].prev = j; } BBPunfix(*bid); (void) ret; return MAL_SUCCEED;}strPBMdepositIndexed(int *ret, str *grp, int *idx){ return PBMdeposit(ret,grp,0,idx);}strPBMdepositByName(int *ret, str *grp, str *elm, str *nme){ int idx; BAT *b; idx= PBMfindPBATcomponent(*grp,*elm); if( idx >=0 ) throw(MAL, "pbm.deposit", "PBAT already known"); idx= BBPindex(*nme); b = BATdescriptor(idx); if (b == NULL) throw(MAL, "pbm.deposit", "Can not access descriptor"); PBMdeposit(ret,grp,elm,&idx); BBPunfix(idx); (void) ret; return MAL_SUCCEED;}strPBMgetRange(oid *first, oid *last, int *bid){ int i; for (i = 0; i < ptop; i++) if (partitions[i].bid == *bid) { *first = partitions[i].hmin.val.oval; *last = partitions[i].hmax.val.oval; return MAL_SUCCEED; } throw(MAL, "pbm.getRange", "PBAT not known");}strPBMgetLast(int *ret, str *grp){ int i; i= PBMfindPBAT(*grp); if( i < 0) throw(MAL, "pbm.getLast", "PBAT not known"); for (; partitions[i].next>=0 ; i= partitions[i].next) ; *ret = partitions[i].bid; return MAL_SUCCEED;}strPBMdiscard(int *ret, str *grp){ int i; for (i = 0; i<ptop; i++) if( partitions[i].grp && strcmp(partitions[i].grp, *grp)== 0 ) PBMfreePartition(i); (void) ret; return MAL_SUCCEED;}strPBMdiscardAll(int *ret){ int i; for(i=0; i<ptop; i++) if( partitions[i].grp) PBMfreePartition(i); GDKfree(partitions); partitions = 0; plimit = -1; PBMresize(INCREMENT); (void) ret; return MAL_SUCCEED;}#line 705 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/pbm.mx"strPBMreleaseAll(int *ret, int *bid){ (void) ret; (void) bid; throw(MAL, "pbm.release", "not yet implemented");}strPBMdiscardComponent(int *ret, str *grp, int *bid){ (void) ret; (void) bid; (void) grp; throw(MAL, "pbm.release", "not yet implemented");}#line 729 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/pbm.mx"strPBMnewIteratorBase(int *ret, str *grp, str *elm){ *ret = 0; if (*ret == ptop) *ret = -1; else { *grp= GDKstrdup(partitions[0].grp); *elm= GDKstrdup(partitions[0].elm); } return MAL_SUCCEED;}strPBMnewIterator(int *res, str *grp){ int idx; idx= PBMfindPBAT(*grp); if(idx<0) throw(MAL, "pbm.newIterator","Could not find PBAT"); *res = partitions[idx].bid; BBPincref(*res, TRUE); return MAL_SUCCEED;}strPBMnewIteratorRng(int *res, str *grp, oid *first, oid *last){ int i; i= PBMfindPBAT(*grp); if( i<0) throw(MAL, "pbm.newIterator","Could not find PBAT"); for (; i>=0 ; i= partitions[i].next) if (!(partitions[i].hmax.val.oval < *first || partitions[i].hmin.val.oval > *last)) { *res = partitions[i].bid; BBPincref(*res, TRUE); } return MAL_SUCCEED;}strPBMgetNextElement(int *res, str *grp){ int i; for(i=0; i<ptop; i++) if( partitions[i].bid == *res && partitions[i].grp && strcmp(partitions[i].grp,*grp)== 0){ *res= partitions[i].bid; BBPincref(*res, TRUE); return MAL_SUCCEED; } *res = -1; return MAL_SUCCEED;}strPBMgetNextElementRng(int *res, str *grp, oid *first, oid *last){ int i; for(i= PBMfindPBAT(*grp); i>=0 ; i = partitions[i].next) if( !(partitions[i].hmax.val.oval < *first || partitions[i].hmin.val.oval > *last)) { *res = partitions[i].bid; BBPincref(*res, TRUE); return MAL_SUCCEED; } *res = -1; return MAL_SUCCEED;}strPBMcompress(int *ret, str *grp){ BAT *b; int i; oid o = 0; (void) ret; i = PBMfindPBAT(*grp); if (i < 0) throw(MAL, "pbm.commpress", "PBAT not found"); b = BATdescriptor(partitions[i].bid); if (b == 0) throw(MAL, "pbm.commpress", "BAT group not found"); for (; i >= 0; i = partitions[i].next) { partitions[i].hmin.val.oval = o; b = BATdescriptor(partitions[i].bid); if (b == 0) throw(MAL, "pbm.compress", "Internal error in BAT group"); b->hseqbase = partitions[i].hmin.val.oval; o = partitions[i].hmax.val.oval += BATcount(b) - 1; BBPunfix(b->batCacheid); } return MAL_SUCCEED;}strPBMdummy(int *ret, str *grp){ (void)ret; (void) grp; return MAL_SUCCEED;}strPBMgetNextName(int *ret, str *nme, str *elm){ do { *ret = *ret + 1; if (*ret >= ptop) { *ret = -1; return MAL_SUCCEED; } *nme= GDKstrdup(partitions[*ret].grp); *elm= GDKstrdup(partitions[*ret].elm); } while (partitions[*ret].bid == -1); return MAL_SUCCEED;}#line 851 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/pbm.mx"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -