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

📄 crackers.mx

📁 一个内存数据库的源代码这是服务器端还有客户端
💻 MX
📖 第 1 页 / 共 5 页
字号:
	TreeIndex[i].iid = -1;	TreeIndex[i].did = -1;	TreeIndex[i].mergeInsertions = -1;	TreeIndex[i].reCreate = 0;	TreeIndex[i].Tree = NULL;	TreeIndex[i].deleteNodes = FALSE;	TreeIndex[i].mergeDeletions = -1;	return i;}voidreCreateMap_@1(int position){	BAT *b;	b = BATnew(TYPE_lng, TYPE_@1, IndexEntries);	/* TODO: size */	BBPkeepref(b->batCacheid);	TreeIndex[position].cid = b->batCacheid;	TreeIndex[position].reCreate = 0;		return;}intnewIndex_@1(int bid, int cbid){	int i, freemap = -1, units = 1024;	BAT *b;		for (i = 0; i < maxCrackMap; i++)		if (Index[i].bid == -1)			freemap = i;	if (freemap != -1) {		Index[freemap].bid = bid;		return freemap;	}	if (i == maxCrackMap) {		CrackIndex *x;		if (maxCrackMap > 0)			units = (int) (1.2 * maxCrackMap);		x = (CrackIndex *) GDKmalloc(sizeof(CrackIndex) * units);		memset(x, 0, sizeof(CrackIndex) * units);		if (Index) {			fprintf(stderr, "reallocate index \n");			memcpy(x, Index, sizeof(CrackIndex) * i);			GDKfree(Index);		}		Index = x;		maxCrackMap = units;	}	Index[i].bid = bid;	Index[i].cbid = cbid;	b = BATnew(TYPE_lng, TYPE_@1, 220000);	/*todo: size*/	BBPkeepref(b->batCacheid);	Index[i].cid = b->batCacheid;	return i;}intnewAVLIndex_@1(int bid){        int i, freemap = -1, units = 1024;        for (i = 0; i < maxCrackMap; i++)                if (AVLIndex[i].bid == -1)                        freemap = i;        if (freemap != -1) {                AVLIndex[freemap].bid = bid;                return freemap;        }        if (i == maxCrackMap) {                AVLTreeIndex *x;                if (maxCrackMap > 0)                        units = (int) (1.2 * maxCrackMap);                x = (AVLTreeIndex *) GDKmalloc(sizeof(AVLTreeIndex) * units);                memset(x, 0, sizeof(AVLTreeIndex) * units);                if (AVLIndex) {                        fprintf(stderr, "reallocate index \n");                        memcpy(x, AVLIndex, sizeof(AVLTreeIndex) * i);                        GDKfree(AVLIndex);                }                AVLIndex = x;                maxCrackMap = units;        }        AVLIndex[i].bid = bid;        AVLIndex[i].Tree = NULL;        return i;}@@c@:CreateNewIndex(chr)@@:CreateNewIndex(sht)@@:CreateNewIndex(int)@@:CreateNewIndex(lng)@@:CreateNewIndex(flt)@@:CreateNewIndex(dbl)@@:CreateNewIndex(date)@voidprintCrackerIndex(int bid){	int i = existsTreeIndex(bid);	if (i == -1)		fprintf(stderr, " the crack index does not exist \n");	BATprint(BATdescriptor(TreeIndex[i].cid));}strCRKprintCrackerIndex(int *k, int *bid){	(void)k;	printCrackerIndex(*bid);	return MAL_SUCCEED;}voidprintCrackerBAT(int bid){	int i = existsTreeIndex(bid);	if (i == -1)		fprintf(stderr, " the crack index does not exist \n");	BATprint(BATdescriptor(TreeIndex[i].cbid));}voidprintCrackerDeletions(int bid){	int i = existsTreeIndex(bid);	if (i == -1)		fprintf(stderr, " the crack index does not exist \n");	if (TreeIndex[i].did > 0)		BATprint(BATdescriptor(TreeIndex[i].did));}voidprintCrackerInsertions(int bid){	int i = existsTreeIndex(bid);	if (i == -1)		fprintf(stderr, " the crack index does not exist \n");	if (TreeIndex[i].iid > 0)		BATprint(BATdescriptor(TreeIndex[i].iid));}strCRKprintCrackerBAT(int *k, int *bid){	(void)k;	printCrackerBAT(*bid);	return MAL_SUCCEED;}strCRKgetCrackerBAT(int *vid, int *bid){        int i = existsTreeIndex(*bid);        if (i == -1)                fprintf(stderr, " the cracker index does not exist \n");        if (TreeIndex[i].cbid > 0)		*vid = TreeIndex[i].cbid;	else		*vid = -1;        return MAL_SUCCEED;}voidsizeCrackerDeletions(int bid){        BAT *u;        int i = existsTreeIndex(bid);        if (i == -1)                fprintf(stderr, " the crack index does not exist \n");        if (TreeIndex[i].did > 0){                u = BATdescriptor(TreeIndex[i].did);                printf("\n pending deletions size: "SZFMT"\n",BATcount(u));                BBPunfix(u->batCacheid);        }        else                printf("\n pending deletions size: 0 \n");}strCRKsizeCrackerDeletions(int *k, int *bid){        (void)k;        sizeCrackerDeletions(*bid);        return MAL_SUCCEED;}voidsizeCrackerInsertions(int bid){	BAT *u;	int i = existsTreeIndex(bid);	if (i == -1)		fprintf(stderr, " the crack index does not exist \n");	if (TreeIndex[i].iid > 0){		u = BATdescriptor(TreeIndex[i].iid);		printf("\n pending insertions size: "SZFMT" \n",BATcount(u));		BBPunfix(u->batCacheid);	}	else		printf("\n pending insertions size: 0 \n");}strCRKsizeCrackerInsertions(int *k, int *bid){	(void)k;	sizeCrackerInsertions(*bid);	return MAL_SUCCEED;}strCRKprintCrackerDeletions(int *k, int *bid){	(void)k;	printCrackerDeletions(*bid);	return MAL_SUCCEED;}strCRKprintCrackerInsertions(int *k, int *bid){	(void)k;	printCrackerInsertions(*bid);	return MAL_SUCCEED;}@= insertIndexElement	*(lng*) @2 = @4;		*(@1 *) @3 = @5;		(b)->batBuns->free += xx;        (b)->batCount ++;@@= InsertIndexElementsvoidaddTreeIndex_@1(int m, @1 *value, bit inclusive, lng index, BAT * b){	BUN ph,pt,base;        int xx = BUNsize(b);	ph = BUNhloc(b, BUNlast(b));	pt = BUNtloc(b, BUNlast(b));        if (BATcount(b) == 0){                @:insertIndexElement(@1, BUNhloc(b, BUNfirst(b)), BUNtloc(b, BUNfirst(b)), index, *value)@		TreeIndex[m].Tree = (struct Node *)GDKmalloc(sizeof(struct Node));                TreeIndex[m].Tree->position = 0;                TreeIndex[m].Tree->inclusive = inclusive;                TreeIndex[m].Tree->height = 0;                TreeIndex[m].Tree->left = NULL;                TreeIndex[m].Tree->right = NULL;		                TreeIndex[m].Tree->head = TRUE;	                TreeIndex[m].Tree->deleted = FALSE;	                TreeIndex[m].Tree->previous = NULL;	                TreeIndex[m].Tree->hols = 0;	                return;        }	base = BUNhloc(b, BUNfirst(b));        if ( (InsertTree_@1(m, BATcount(b), *value, inclusive, index, TreeIndex[m].Tree, b, base, xx)) != NULL ) {		/* use a new BUN only if we cannot reuse a previously deleted one */		@:insertIndexElement(@1, ph, pt, index, *value)@	}}voidaddOne_@1(int i, @1 *value, lng index, BUN p){	BAT *b;	int xx;	BUN ph, pt, wh, wt, rh, rt;	if ((b = BATdescriptor(Index[i].cid)) == NULL) {		fprintf(stderr,"crackers.AddIndex: Cannot access crack index");		return;	}	xx = BUNsize(b);	if (BATcount(b) == 0){		@:insertIndexElement(@1,BUNhloc(b, BUNfirst(b)), BUNtloc(b, BUNfirst(b)), index, *value)@		return; 			}	/*todo: check BAT size*/	ph = BUNhloc(b, p);	pt = BUNtloc(b, p);		if (p == BUNlast(b)){ /*Insert at the end if everything is smaller than the new value*/		@:insertIndexElement(@1, ph, pt, index, *value)@		return;	}	/*Else we have to sift some buns to put the new one to the right position*/	wh = BUNhloc(b, BUNlast(b));	wt = BUNtloc(b, BUNlast(b));	rh = wh - xx, rt = wt - xx;	if (@2_EQ(pt,value,@3@1) && index > 0){ /*negative index values inidicate non inclusive bounds so they should be always first*/		ph += xx;		pt += xx;	}	for (;rt>=pt;rh-=xx,wh-=xx,rt-=xx,wt-=xx){		*(lng*)wh = *(lng*)rh;		*(@1 *)wt = *(@1 *)rt;	}	@:insertIndexElement(@1, ph, pt, index, *value)@	BBPunfix(b->batCacheid);}	voidaddTwo_@1(int i, @1 *valueA, lng indexA, BUN p2, @1 *valueB, lng indexB, BUN p){	BAT *b;	int xx;	BUN ph, pt, wh, wt, rh, rt, p2h, p2t;        if ((b = BATdescriptor(Index[i].cid)) == NULL) {                fprintf(stderr,"crackers.AddIndex: Cannot access crack index");		return;        }	/*todo: check BAT size*/	xx = BUNsize(b);	if (BATcount(b) == 0){		BUN ph = BUNhloc(b, BUNfirst(b));		BUN pt = BUNtloc(b, BUNfirst(b));		@:insertIndexElement(@1, ph, pt, indexA, *valueA)@		ph += xx;		pt += xx;		@:insertIndexElement(@1, ph, pt, indexB, *valueB)@		return; 			}	ph = BUNhloc(b, p);	pt = BUNtloc(b, p);	wh = BUNhloc(b, BUNlast(b)+xx);	wt = BUNtloc(b, BUNlast(b)+xx);	rh = wh - 2*xx;	rt = wt - 2*xx;        p2h = BUNhloc(b, p2);        p2t = BUNtloc(b, p2);	if (p == BUNlast(b)){		ph += xx; /* sift one more position to make room for pair A too*/		pt += xx;		@:insertIndexElement(@1, ph, pt, indexB, *valueB)@	}	else{   /*Else we have to sift some buns to put the new one to the right position*/		if (@2_EQ(pt,valueB,@3@1) && indexB > 0){			ph += xx;			pt += xx;		}		for (;rt>=pt;rh-=xx,wh-=xx,rt-=xx,wt-=xx){			*(lng*)wh = *(lng*)rh;			*(@1 *)wt = *(@1 *)rt;		}		ph += xx; /* sift one more position to make room for pair A too*/		pt += xx;		@:insertIndexElement(@1, ph, pt, indexB, *valueB)@	}        wh -= xx;        wt -= xx;        if (@2_EQ(p2t,valueA,@3@1) && indexA > 0){                p2h += xx;                p2t += xx;        }        for (;rt>=p2t;rh-=xx,wh-=xx,rt-=xx,wt-=xx){                *(lng*)wh = *(lng*)rh;                *(@1 *)wt = *(@1 *)rt;        }        @:insertIndexElement(@1, p2h, p2t, indexA, *valueA)@	BBPunfix(b->batCacheid);}	voidaddAVLIndex_@1(int m,  lng position, BAT * b){        BUN base;        int xx = BUNsize(b);        if (position == 0){                AVLIndex[m].Tree = (struct Node *)GDKmalloc(sizeof(struct Node));                AVLIndex[m].Tree->position = position;                AVLIndex[m].Tree->inclusive = TRUE;                AVLIndex[m].Tree->height = 0;                AVLIndex[m].Tree->left = NULL;                AVLIndex[m].Tree->right = NULL;                AVLIndex[m].Tree->head = TRUE;                AVLIndex[m].Tree->deleted = FALSE;                AVLIndex[m].Tree->previous = NULL;                return;        }        base = BUNhloc(b, BUNfirst(b));        InsertAVLIndex_@1(m, position, *(@1*)BUNtloc(b,base+position*xx),  AVLIndex[m].Tree, b, base, xx);}crackers_export str CRKmakeAVLIndex_@1(int *k, int *bid);strCRKmakeAVLIndex_@1(int *k, int *bid){	BUN last, cur;	int indexPos;	int xx;	lng curPos;	BAT *b;	(void) k;        if ((b = BATdescriptor(*bid)) == NULL)		throw(MAL, "crackers.make AVL index", "Cannot access descriptor");	indexPos = newAVLIndex_@1(*bid);	cur = BUNfirst(b);	last = BUNlast(b);	xx = BUNsize(b);	curPos = 0;	while (cur < last){		addAVLIndex_@1(indexPos,curPos,b);		cur+=xx;		curPos++;	}		BBPunfix(b->batCacheid);	return MAL_SUCCEED;}crackers_export str CRKInsertAVLIndex_@1(int *k, int *bid, int *uid);strCRKInsertAVLIndex_@1(int *k, int *bid, int *uid){	BUN last, cur;	int indexPos;	int xx;	lng curPos;

⌨️ 快捷键说明

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