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

📄 aggr.mx

📁 一个内存数据库的源代码这是服务器端还有客户端
💻 MX
📖 第 1 页 / 共 5 页
字号:
		if (!simple_EQ(BUNtloc(b,p),bt_nil,{chr,sht,int,flt,lng,dbl}))*/@= aggrX3_count_loop	ALGODEBUG THRprintf(GDKout, "#aggrX3_count_loop(@1,@2,@3,@4,@5,@6,@7);\n");	BATloopFast(b, p, q, xx) {		oid *h = (oid*) @5;		@3(r, bn, h);		if (r) {			@7 {				int *dst = (int*) @6;				(*dst)++;			}		}	}	break;@cintCMDaggrX3_count(BAT **ret, BAT *b, BAT *e, bit *ignore_nils){	BAT *bn;	int zero = 0, *cnt;	BUN p, q, r;	int xx;	size_t range;	oid min, max;	oid bhsb;	int btt;	ptr bt_nil = ATOMnilptr(b->ttype);	ALGODEBUG THRprintf(GDKout, "#CMDaggrX3_count(b=%s,e=%s);\n", 		BATgetId(b),BATgetId(e));	if (e->htype == TYPE_void && e->ttype == TYPE_void &&	    b->htype == TYPE_void && BATcount(b) == BATcount(e)) {		/* simply return counts with one */		int one = 1;		bn = BATconst(b, TYPE_int, &one);		*ret = bn;		return GDK_SUCCEED;	} 	bn = BATnew(e->htype, TYPE_int, BATcount(e));	if (bn == NULL)		return GDK_FAIL;	/* init: set all counts to zero and calculate min/max oid */	@:init_result(int)@	range = max - min + 1;	/* scan b, and calculate counts */	if (e->htype == TYPE_void) {		/* void lookup */		if (b->htype == TYPE_void) {			@:aggrX3_count(0,0,BUNfndVOID,var,&bhsb;bhsb++,BUNtloc(bn,r))@		} else {			@:aggrX3_count(0,0,BUNfndVOID,var,BUNhloc(b,p),BUNtloc(bn,r))@		}		/* e->htype == TYPE_oid */	} else if (range > SMALL_AGGR_MAX) {		/* hash lookup */		if (b->htype == TYPE_void) {			@:aggrX3_count(0,1,HASHfnd_oid,loc,&bhsb;bhsb++,BUNtloc(bn,r))@		} else {			@:aggrX3_count(0,1,HASHfnd_oid,loc,BUNhloc(b,p),BUNtloc(bn,r))@		}	} else {		/* array lookup */		if (b->htype == TYPE_void) {			@:aggrX3_count(1,0,CHKrange,loc,&bhsb;bhsb++,&cnt[(*(oid*)h)-min])@		} else {			@:aggrX3_count(1,0,CHKrange,loc,BUNhloc(b,p),&cnt[(*(oid*)h)-min])@		}	}	*ret = bn;	return GDK_SUCCEED;}@- Size@cintCMDaggrX3_size(BAT **ret, BAT *b, BAT *e){	BAT *bn = BATnew(e->htype, TYPE_int, BATcount(e));	int zero = 0;	BUN p, q, r;	int xx;	if (bn == NULL)		return GDK_FAIL;	/* init: set all sums to zero */	bn->tsorted = bn->hsorted = 0;	ALIGNsetH(bn, e);	BATloopFast(e, p, q, xx) {		if (BUNfastins(bn, BUNhead(e, p), &zero) == NULL) {			BBPreclaim(bn);			return GDK_FAIL;		}	}	/* scan b, and add increment totals for true values */	if (BATprepareHash(bn)) {		BBPreclaim(bn);		return GDK_FAIL;	}	BATloopFast(b, p, q, xx) {		if (*(bit *) BUNtloc(b, p) == TRUE) {			oid *h = (oid *) BUNhead(b, p);			BUNfndOID(r, bn, h);			if (r) {				int *dst = (int *) BUNtloc(bn, r);				(*dst)++;			}		}	}	*ret = bn;	return GDK_SUCCEED;}@- Sum, Product & Average@c/*	aggrX3_sum3		e-void-head	e-oid-head	e-oid-head		void-lookup	hash-lookup	array-lookup	@1:	0		0		1		use sums-array?	@2:	0		1		0		do BATprepareHash?	@3:	BUNfndVOID	HASHfnd_oid	CHKrange	lookup	@4:	var		loc		loc		e/bn-head-access	@5:	"BUNhloc(b,p)"	for  (oid) b-head-type,		b-head access		"&bhsb; bhsb++" for (void) b-head-type	@6:		sht / int / lng / flt / dbl		b/bn-tail-type#	not used any more as the result-type needs an argument#	@7:	"loc" for fixsized b/bn-tail-type,		b/bn-tail-access#		"var" for varsized b/bn-tail-type		(only loc used currently)	@7:	BUNt@7(bn,r)	BUNt@7(bn,r)	&sums[(*(oid*)h)-min]								*dst: sum in-place or in sums-array ?	@8:	<empty> / if (w >= base && w < end)		check head (oid) ranges in case b & g								are not void-headed and aligned	@9:	result type*/@= aggrX3_sum3	ALGODEBUG THRprintf(GDKout, "#aggrX3_sum3(@1,@2,@3,@4,@5,@6,@7,@8,@9);\n");	if (@1) {		/* create tmp. sums array */		size_t i;		sums = (@9*) GDKmalloc(range*sizeof(@9));		for (i = 0; i < range; i++)			sums[i] = zero;	}	if (@2 && BATprepareHash(bn)) {		if (@1)			GDKfree(sums);		BBPreclaim(bn);		return GDK_FAIL;	}	/* scan b & g, and add values to sums in-place or in sums-array */	base = BUNindex(g, BUNfirst(g));	offset = (ssize_t) (base - g->hseqbase);	end = base + BATcount(g);	(void) end;		/* keep compilers happy */	bhsb = b->hseqbase;	BATloopFast(b, p, q, xx) {		@6 *t = (@6*) BUNtloc(b,p);		oid v = *(oid*) @5;		w = offset + v;		@8 {			oid *h = (oid*) BUNtloc(g, BUNptr(g, w));			@3(r, bn, (oid*)h);			if (r) {				@9 *dst = (@9*) @7;				if (*dst != @9_nil) {					if (*t == @6_nil) {						*dst = @9_nil;					} else {						*dst += *t;					}				}			}		}	}	if (@1) {		/* copy sums array to final result */		BATloopFast(bn, p, q, xx) {			oid h = (*(oid*) BUNh@4(bn,p)) - min;			*(@9*)BUNtloc(bn, p) = sums[h];		}		GDKfree(sums);	}@@c/*	aggrX3_prod3		e-void-head	e-oid-head	e-oid-head		void-lookup	hash-lookup	array-lookup	@1:	0		0		1		use prods-array?	@2:	0		1		0		do BATprepareHash?	@3:	BUNfndVOID	HASHfnd_oid	CHKrange	lookup	@4:	var		loc		loc		e/bn-head-access	@5:	"BUNhloc(b,p)"	for  (oid) b-head-type,		b-head access		"&bhsb; bhsb++" for (void) b-head-type	@6:		sht / int / lng / flt / dbl		b/bn-tail-type#	not used any more as the result-type needs an argument#	@7:	"loc" for fixsized b/bn-tail-type,		b/bn-tail-access#		"var" for varsized b/bn-tail-type		(only loc used currently)	@7:	BUNt@7(bn,r)	BUNt@7(bn,r)	&prods[(*(oid*)h)-min]								*dst: prod in-place or in prods-array ?	@8:	<empty> / if (w >= base && w < end)		check head (oid) ranges in case b & g								are not void-headed and aligned	@9:	result type*/@= aggrX3_prod3	ALGODEBUG THRprintf(GDKout, "#aggrX3_prod3(@1,@2,@3,@4,@5,@6,@7,@8,@9);\n");	if (@1) {		/* create tmp. prods array */		size_t i;		prods = (@9*) GDKmalloc(range*sizeof(@9));		for (i = 0; i < range; i++)			prods[i] = zero;	}	if (@2 && BATprepareHash(bn)) {		if (@1)			GDKfree(prods);		BBPreclaim(bn);		return GDK_FAIL;	}	/* scan b & g, and add values to prods in-place or in prods-array */	base = BUNindex(g, BUNfirst(g));	offset = (ssize_t) (base - g->hseqbase);	end = base + BATcount(g);	(void) end;		/* keep compilers happy */	bhsb = b->hseqbase;	BATloopFast(b, p, q, xx) {		@6 *t = (@6*) BUNtloc(b,p);		oid v = *(oid*) @5;		w = offset + v;		@8 {			oid *h = (oid*) BUNtloc(g, BUNptr(g, w));			@3(r, bn, (oid*)h);			if (r) {				@9 *dst = (@9*) @7;				if (*dst != @9_nil) {					if (*t == @6_nil) {						*dst = @9_nil;					} else {						*dst *= *t;					}				}			}		}	}	if (@1) {		/* copy prods array to final result */		BATloopFast(bn, p, q, xx) {			oid h = (*(oid*) BUNh@4(bn,p)) - min;			*(@9*)BUNtloc(bn, p) = prods[h];		}		GDKfree(prods);	}@@c/*	aggrX3_avg3		e-void-head	e-oid-head	e-oid-head		void-lookup	hash-lookup	array-lookup	@1:	0		0		1		use sums-array?	@2:	0		1		0		do BATprepareHash?	@3:	BUNfndVOID	HASHfnd_oid	CHKrange	lookup	@4:	var		loc		loc		e/bn-head-access	@5:	"BUNhloc(b,p)"	for  (oid) b-head-type,		b-head access		"&bhsb; bhsb++" for (void) b-head-type	@6:		sht / int / lng / flt / dbl		b/bn-tail-type	@7:	"loc" for fixsized b/bn-tail-type,		b/bn-tail-access		"var" for varsized b/bn-tail-type		(only loc used currently)	@8:	BUNt@7(bn,r)	BUNt@7(bn,r)	&sums[(*(oid*)h)-min]								*dst: sum in-place or in sums-array ?	@9:		BUNindex(bn,r)-off		(*(oid*)h)-min	index in cnt array*/@= aggrX3_avg3	ALGODEBUG THRprintf(GDKout, "#aggrX3_avg3(@1,@2,@3,@4,@5,@6,@7,@8,@9);\n");	if (@1) {		/* create tmp. sums array */		size_t i;		sums = (dbl*) GDKmalloc(range*sizeof(dbl));		for (i = 0; i < range; i++)			sums[i] = zero;	}	if (@2 && BATprepareHash(bn)) {		if (@1)			GDKfree(sums);		BBPreclaim(bn);		return GDK_FAIL;	}	cnt = (size_t*) GDKmalloc(slots*sizeof(cnt[0]));	memset(cnt, 0, slots*sizeof(cnt[0]));	/* scan b & g, adding sums, and incrementing counts */	base = BUNindex(g, BUNfirst(g));	offset = (ssize_t) (base - g->hseqbase);	end = base + BATcount(g);	(void) end;		/* keep compilers happy */	bhsb = b->hseqbase;	BATloopFast(b, p, q, xx) {		@6 *t = (@6*) BUNt@7(b,p);		oid v = *(oid*) @5;		w = offset + v;		if (w >= base && w < end) {			oid *h = (oid*) BUNtloc(g, BUNptr(g, w));			@3(r, bn, (oid*)h);			if (r) {				dbl *dst = (dbl*) @8;				if (*dst != dbl_nil) {					if (*t == @6_nil) {						*dst = dbl_nil;					} else {						*dst += *t;					}					cnt[@9]++;				}			}		}	}	/* postprocess by dividing sums by counts */	if (@1) {		/* sums in sums-array */		BATloopFast(bn, p, q, xx) {			oid h = (*(oid*) BUNh@4(bn,p)) - min;			dbl *dst = (dbl*) BUNt@7(bn, p);			if (cnt[h] == 0 || sums[h] == dbl_nil) {				*dst = dbl_nil;			} else {				*dst = sums[h]/cnt[h];			}		}		GDKfree(sums);	} else {		/* sums in-place */		size_t yy = 0;		BATloopFast(bn, p, q, xx) {			dbl *dst = (dbl*) BUNt@7(bn, p);			if (cnt[yy] == 0) {				*dst = dbl_nil;			} else if (*dst != dbl_nil) {				*dst /= cnt[yy];			}			yy++;		}	}	GDKfree(cnt);@c/*	arithsum3	@6:	sht / int / lng / flt / dbl		b/bn-tail-type#	not used any more#	@7:	"loc" for fixsized b/bn-tail-type,	b/bn-tail-access#		"var" for varsized b/bn-tail-type	(only loc used currently)	@9:	result type*/@= arithsum3static intaggrX3_sum3_@1_@2_EarrayBvoidGvoid (BAT *bn, BAT *b, BAT *g, BAT *e, size_t range, oid min, oid max){	@2 zero = (@2) 0, *sums;	BUN p, q, r;	int xx;	oid bhsb;	size_t base, end, w;	ssize_t offset;	ALGODEBUG THRprintf(GDKout, "#aggrX3_sum3_@1_@2_EarrayBvoidGvoid(bn=%s,b=%s,g=%s,e=%s,range=" SZFMT ",min=" SZFMT ",max=" SZFMT ");\n",				BATgetId(bn),BATgetId(b),BATgetId(g),BATgetId(e),				range,(size_t) min,(size_t) max);	@:aggrX3_sum3(1,0,CHKrange,loc,&bhsb;bhsb++,@1,&sums[(*(oid*)h)-min],,@2)@	return GDK_SUCCEED;}intCMDaggrX3_sum3_@1_@2(BAT **ret, BAT *b, BAT *g, BAT *e){	BAT *bn = BATnew(e->htype, TYPE_@2, BATcount(e));	@2 zero = (@2) 0, *sums;	BUN p, q, r;	int xx;	size_t range;	oid min, max;	oid bhsb;	size_t base, end, w;	ssize_t offset;	if( bn == NULL)		return GDK_FAIL;	ALGODEBUG THRprintf(GDKout, "#CMDaggrX3_sum3_@1_@2(b=%s,g=%s,e=%s);\n",		BATgetId(b),BATgetId(g), BATgetId(e));/*	ERRORcheck((BATcount(b)!=BATcount(g)), "CMDaggrX3_sum3_@1: BATs b & g must be of equal size.\n");	*/	ERRORcheck((g->htype == TYPE_void) && (g->hseqbase == oid_nil) && (BATcount(g) > 0), "CMDaggrX3_sum3_@1: head of BAT g must not be nil.\n");	if((g->hseqbase == oid_nil) || (!BAThdense(g)) || (!(BAThordered(b)&1)) || (!g->hkey)) {		return CMDaggrX3_sum_@1_@2(ret, BATjoin(BATmirror(g),b,oid_nil), e);	}	*ret = bn;	/* init: set all sums to zero and calculate min/max oid */	@:init_result(@2)@	range = max - min + 1;	/* scan b & g, and calculate sums */	if (e->htype == TYPE_void) {		/* void lookup */		if (b->htype == TYPE_void) {			if ((g->htype == TYPE_void)&&(BATcount(b)==BATcount(g))&&(b->hseqbase==g->hseqbase)) {				@:aggrX3_sum3(0,0,BUNfndVOID,var,&bhsb;bhsb++,@1,BUNtloc(bn,r),,@2)@			} else {				@:aggrX3_sum3(0,0,BUNfndVOID,var,&bhsb;bhsb++,@1,BUNtloc(bn,r),if (w >= base && w < end),@2)@			}		} else {			@:aggrX3_sum3(0,0,BUNfndVOID,var,BUNhloc(b,p),@1,BUNtloc(bn,r),if (w >= base && w < end),@2)@		}	/* e->htype == TYPE_oid */	} else if (range > SMALL_AGGR_MAX) {		/* hash lookup */		if (b->htype == TYPE_void) {			if ((g->htype == TYPE_void)&&(BATcount(b)==BATcount(g))&&(b->hseqbase==g->hseqbase)) {				@:aggrX3_sum3(0,1,HASHfnd_oid,loc,&bhsb;bhsb++,@1,BUNtloc(bn,r),,@2)@			} else {				@:aggrX3_sum3(0,1,HASHfnd_oid,loc,&bhsb;bhsb++,@1,BUNtloc(bn,r),if (w >= base && w < end),@2)@			}		} else {			@:aggrX3_sum3(0,1,HASHfnd_oid,loc,BUNhloc(b,p),@1,BUNtloc(bn,r),if (w >= base && w < end),@2)@		}	} else {		/* array lookup */		if (b->htype == TYPE_void) {			if ((g->htype == TYPE_void)&&(BATcount(b)==BATcount(g))&&(b->hseqbase==g->hseqbase)) {				return aggrX3_sum3_@1_@2_EarrayBvoidGvoid (bn, b, g, e, range, min, max);			} else {				@:aggrX3_sum3(1,0,CHKrange,loc,&bhsb;bhsb++,@1,&sums[(*(oid*)h)-min],if (w >= base && w < end),@2)@			}		} else {			@:aggrX3_sum3(1,0,CHKrange,loc,BUNhloc(b,p),@1,&sums[(*(oid*)h)-min],if (w >= base && w < end),@2)@		}	}	return GDK_SUCCEED;}@c

⌨️ 快捷键说明

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