⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pbm.mx

📁 一个内存数据库的源代码这是服务器端还有客户端
💻 MX
📖 第 1 页 / 共 2 页
字号:
	destroyBox("partitions");	return MAL_SUCCEED;}@-Taking out a BAT should be protective, i.e. check for their existence.Taking out a PBAT leads to a forced union before returning.The intend is to use an optimizer to avoid this if possible.@cstrPBMtakeComplete(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;}@-Administration of new partitions.@cintPBMfindGrp(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;}@-Find the header of a group@cintPBMfindPBAT(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;}@-releasing the PBAT does not remove its components.@cstrPBMreleaseAll(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");}@-We start with the large chunk iterator.The definition of the control statements require the samecontrol variables, which means that the BATview is accessibleto determine how far to advance when the next chunk is retrieved.The number of elements in the chunk is limited by the granulesize.@cstrPBMnewIteratorBase(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;}@}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -