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

📄 algebra.c

📁 一个内存数据库的源代码这是服务器端还有客户端
💻 C
📖 第 1 页 / 共 5 页
字号:
CMDfetchbat(BAT **ret, BAT *b, BAT *s){	return (*ret = BATfetch(b, s)) ? GDK_SUCCEED : GDK_FAIL;}intdoCMDfetch(ptr ret, BAT *b, lng i){	if (i < 0 || i >= (lng) BATcount(b)) {		GDKerror("CMDfetch: idx out of range\n");		return GDK_FAIL;	}	i += BUNindex(b, BUNfirst(b));	#line 1476 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/algebra.mx"	if (b->ttype && b->theap) {		ptr _src = BUNtvar(b,BUNptr(b,(size_t)i));/*b->theap->base + *(var_t*) BUNtloc(b,BUNptr(b,(size_t)i));*/		int _len = ATOMlen(b->ttype, _src);		ptr _dst = GDKmalloc(_len);		memcpy(_dst, _src, _len);		*(ptr*) ret = _dst;	} else {		int _s = ATOMsize(ATOMtype(b->ttype));		if (ATOMvarsized(b->ttype)) {			memcpy(*(ptr*) ret=GDKmalloc(_s), BUNtvar(b, BUNptr(b,(size_t)i)), _s);		} else if (b->ttype == TYPE_bat) {			bat bid = *(bat*) BUNtloc(b, BUNptr(b,(size_t)i));			*(BAT**) ret = BATdescriptor(bid);		} else if (_s == 4) {			*(int*) ret = *(int*) BUNtail(b, BUNptr(b,(size_t)i));		} else if (_s == 1) {			*(chr*) ret = *(chr*) BUNtail(b, BUNptr(b,(size_t)i));		} else if (_s == 2) {			*(sht*) ret = *(sht*) BUNtail(b, BUNptr(b,(size_t)i));		} else if (_s == 8) {			*(lng*) ret = *(lng*) BUNtail(b, BUNptr(b,(size_t)i));		} else {			memcpy(ret, BUNtloc(b, BUNptr(b,(size_t)i)), _s);		}	}#line 1474 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/algebra.mx"#line 1502 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/algebra.mx"	return GDK_SUCCEED;}intCMDfetch(ptr ret, BAT *b, lng *pos){	return doCMDfetch(ret, b, (size_t) * pos);}intCMDfetchoid(ptr ret, BAT *b, oid *pos){	if (b->hseqbase == oid_nil) {		GDKerror("CMDfetchoid: void lookup on uninitialized column.\n");		return GDK_FAIL;	}	return doCMDfetch(ret, b, (size_t) (*pos - b->hseqbase));}intCMDexist(bit *ret, BAT *b, ptr val){	ptr p = (b->htype == TYPE_bat) ? (ptr) &((BAT *) val)->batCacheid : val;	BUN q = BUNfnd(b, p);	*ret = q ? 1 : 0;	return GDK_SUCCEED;}intCMDtexist(bit *ret, BAT *b, ptr val){	return CMDexist(ret, BATmirror(b), val);}intCMDexistBUN(bit *ret, BAT *b, ptr val, ptr tval){	ptr p = (b->htype == TYPE_bat) ? (ptr) &((BAT *) val)->batCacheid : val;	ptr o = (b->ttype == TYPE_bat) ? (ptr) &((BAT *) tval)->batCacheid : tval;	BUN q = BUNlocate(b, p, o);	*ret = q ? 1 : 0;	return GDK_SUCCEED;}intCMDfind(ptr ret, BAT *b, ptr val){	ptr p = (b->htype == TYPE_bat) ? (ptr) &((BAT *) val)->batCacheid : val;	BUN q = BUNfnd(b, p);	if (q == NULL) {		GDKerror("CMDfind: value not found.\n");		return GDK_FAIL;	}	#line 1476 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/algebra.mx"	if (b->ttype && b->theap) {		ptr _src = BUNtvar(b,q);/*b->theap->base + *(var_t*) BUNtloc(b,q);*/		int _len = ATOMlen(b->ttype, _src);		ptr _dst = GDKmalloc(_len);		memcpy(_dst, _src, _len);		*(ptr*) ret = _dst;	} else {		int _s = ATOMsize(ATOMtype(b->ttype));		if (ATOMvarsized(b->ttype)) {			memcpy(*(ptr*) ret=GDKmalloc(_s), BUNtvar(b, q), _s);		} else if (b->ttype == TYPE_bat) {			bat bid = *(bat*) BUNtloc(b, q);			*(BAT**) ret = BATdescriptor(bid);		} else if (_s == 4) {			*(int*) ret = *(int*) BUNtail(b, q);		} else if (_s == 1) {			*(chr*) ret = *(chr*) BUNtail(b, q);		} else if (_s == 2) {			*(sht*) ret = *(sht*) BUNtail(b, q);		} else if (_s == 8) {			*(lng*) ret = *(lng*) BUNtail(b, q);		} else {			memcpy(ret, BUNtloc(b, q), _s);		}	}#line 1557 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/algebra.mx"	return GDK_SUCCEED;}intCMDfind_oid(ptr ret, BAT *b, oid* val){	return CMDfind(ret, b, (ptr) val); }#line 1712 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/algebra.mx"#line 1568 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/algebra.mx"intCMDrmin_summary(BAT **ret, BAT* b, int *quantiles){	ssize_t cnt = BATcount(b), n = MIN(cnt,*quantiles);	dbl threshold =0, delta = ((dbl) cnt) / (dbl) (MAX(1,n)-1);	BAT *bn = *ret = BATnew(b->ttype, TYPE_oid, n);	int (*cmp)(ptr,ptr) = BATatoms[b->ttype].atomCmp;	if (bn == NULL)		return GDK_FAIL;	bn->hsorted = (1 < 0 ? GDK_SORTED : FALSE);	bn->tsorted = GDK_SORTED;	if (cnt > 0) {		ssize_t yy = 0, bunwidth = 0 - BUNsize(b);		BUN p, bnds[2];		ptr v;		bnds[0 < 1] = BUNfirst(b);		bnds[1 < 0] = BUNlast(b) - BUNsize(b);		for (p=bnds[0], v=BUNtail(b, p); bnds[1] < p; p += bunwidth) {			ptr cur = BUNtail(b,p);			if (cmp(cur, v) < 0)				v = cur;			if (++yy > threshold) {				bunfastins(bn, v, BUNhead(b,p));				threshold += delta;			}		}		bunfastins(bn, v, BUNhead(b,p));	}	if ((BAThordered(bn)&1) == 0)		bn = BATrevert(bn);	if (bn) {		bn->hsorted = GDK_SORTED;		return GDK_SUCCEED;	}bunins_failed:	BBPreclaim(bn);	return GDK_FAIL;}intCMDrmin_higher(oid* ret, BAT *b, ptr v){	if ((BAThordered(b)&1) == 0) {		GDKerror("CMDrmin_higher: %s should be sorted on head\n", BATgetId(b));		return GDK_FAIL;	} else if (BATcount(b) > 0) {		BUN p = NULL;		ssize_t idx;		switch(ATOMstorage(b->htype)) {		case TYPE_chr:			p = SORTfndlast_chr(BATmirror(b),v);			break;		case TYPE_sht:			p = SORTfndlast_sht(BATmirror(b),v);			break;		case TYPE_int:			p = SORTfndlast_int(BATmirror(b),v);			break;		case TYPE_lng:			p = SORTfndlast_lng(BATmirror(b),v);			break;		case TYPE_flt:			p = SORTfndlast_flt(BATmirror(b),v);			break;		case TYPE_dbl:			p = SORTfndlast_dbl(BATmirror(b),v);			break;		default:			if (b->hvarsized ) {				p = SORTfndlast_var(BATmirror(b),v);			} else {				p = SORTfndlast_loc(BATmirror(b),v);			}		}		if (p == NULL) {			p = BUNlast(b);		} else if (1 < 0) {			p -= BUNsize(b);		}		if (p < BUNfirst(b)) {			idx = *(ssize_t*) BUNtail(b,p) - 1;		} else if (p >= BUNlast(b)) {			idx = (*(ssize_t*) BUNtail(b,BUNlast(b)-BUNsize(b))) + 1;		} else {			idx = (*(ssize_t*) BUNtail(b,p)) - 1;		}		*ret = (idx < 0)?0:idx;	} else {		*ret = oid_nil;	}	return GDK_SUCCEED;}intCMDfind_higher(oid *ret, BAT *b, ptr v){	ssize_t idx = (ssize_t) oid_nil;	if ((BAThordered(b)&1) == 0) {		GDKerror("CMDfind_higher: %s should be sorted on head\n", BATgetId(b));		return GDK_FAIL;	} else if (BATcount(b) > 0) {		BUN p = NULL;		switch(ATOMstorage(b->htype)) {		case TYPE_chr:			p = SORTfndlast_chr(BATmirror(b),v);			break;		case TYPE_sht:			p = SORTfndlast_sht(BATmirror(b),v);			break;		case TYPE_int:			p = SORTfndlast_int(BATmirror(b),v);			break;		case TYPE_lng:			p = SORTfndlast_lng(BATmirror(b),v);			break;		case TYPE_flt:			p = SORTfndlast_flt(BATmirror(b),v);			break;		case TYPE_dbl:			p = SORTfndlast_dbl(BATmirror(b),v);			break;		default:			if (b->hvarsized ) {				p = SORTfndlast_var(BATmirror(b),v);			} else {				p = SORTfndlast_loc(BATmirror(b),v);			}		}		if (p) {			idx = *(ssize_t*) BUNtail(b,p);			;		}	}	*ret = (oid) idx;	return GDK_SUCCEED;}#line 1712 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/algebra.mx"#line 1568 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/algebra.mx"intCMDrmax_summary(BAT **ret, BAT* b, int *quantiles){	ssize_t cnt = BATcount(b), n = MIN(cnt,*quantiles);	dbl threshold =0, delta = ((dbl) cnt) / (dbl) (MAX(1,n)-1);	BAT *bn = *ret = BATnew(b->ttype, TYPE_oid, n);	int (*cmp)(ptr,ptr) = BATatoms[b->ttype].atomCmp;	if (bn == NULL)		return GDK_FAIL;	bn->hsorted = (1 > 0 ? GDK_SORTED : FALSE);	bn->tsorted = GDK_SORTED;	if (cnt > 0) {		ssize_t yy = 0, bunwidth = 0 + BUNsize(b);		BUN p, bnds[2];		ptr v;		bnds[0 > 1] = BUNfirst(b);		bnds[1 > 0] = BUNlast(b) - BUNsize(b);		for (p=bnds[0], v=BUNtail(b, p); bnds[1] > p; p += bunwidth) {			ptr cur = BUNtail(b,p);			if (cmp(cur, v) > 0)				v = cur;			if (++yy > threshold) {				bunfastins(bn, v, BUNhead(b,p));				threshold += delta;			}		}		bunfastins(bn, v, BUNhead(b,p));	}	if ((BAThordered(bn)&1) == 0)		bn = BATrevert(bn);	if (bn) {		bn->hsorted = GDK_SORTED;		return GDK_SUCCEED;	}bunins_failed:	BBPreclaim(bn);	return GDK_FAIL;}intCMDrmax_lower(oid* ret, BAT *b, ptr v){	if ((BAThordered(b)&1) == 0) {		GDKerror("CMDrmax_lower: %s should be sorted on head\n", BATgetId(b));		return GDK_FAIL;	} else if (BATcount(b) > 0) {		BUN p = NULL;		ssize_t idx;		switch(ATOMstorage(b->htype)) {		case TYPE_chr:			p = SORTfndfirst_chr(BATmirror(b),v);			break;		case TYPE_sht:			p = SORTfndfirst_sht(BATmirror(b),v);			break;		case TYPE_int:			p = SORTfndfirst_int(BATmirror(b),v);			break;		case TYPE_lng:			p = SORTfndfirst_lng(BATmirror(b),v);			break;		case TYPE_flt:			p = SORTfndfirst_flt(BATmirror(b),v);			break;		case TYPE_dbl:			p = SORTfndfirst_dbl(BATmirror(b),v);			break;		default:			if (b->hvarsized ) {				p = SORTfndfirst_var(BATmirror(b),v);			} else {				p = SORTfndfirst_loc(BATmirror(b),v);			}		}		if (p == NULL) {			p = BUNlast(b);		} else if (1 > 0) {			p -= BUNsize(b);		}		if (p < BUNfirst(b)) {			idx = *(ssize_t*) BUNtail(b,p) - 1;		} else if (p >= BUNlast(b)) {			idx = (*(ssize_t*) BUNtail(b,BUNlast(b)-BUNsize(b))) + 1;		} else {			idx = (*(ssize_t*) BUNtail(b,p)) + 1;		}		*ret = (idx < 0)?0:idx;	} else {		*ret = oid_nil;	}	return GDK_SUCCEED;}intCMDfind_lower(oid *ret, BAT *b, ptr v){	ssize_t idx = (ssize_t) oid_nil;	if ((BAThordered(b)&1) == 0) {		GDKerror("CMDfind_lower: %s should be sorted on head\n", BATgetId(b));		return GDK_FAIL;	} else if (BATcount(b) > 0) {		BUN p = NULL;		switch(ATOMstorage(b->htype)) {		case TYPE_chr:			p = SORTfndfirst_chr(BATmirror(b),v);			break;		case TYPE_sht:			p = SORTfndfirst_sht(BATmirror(b),v);			break;		case TYPE_int:			p = SORTfndfirst_int(BATmirror(b),v);			break;		case TYPE_lng:			p = SORTfndfirst_lng(BATmirror(b),v);			break;		case TYPE_flt:			p = SORTfndfirst_flt(BATmirror(b),v);			break;		case TYPE_dbl:			p = SORTfndfirst_dbl(BATmirror(b),v);			break;		default:			if (b->hvarsized ) {				p = SORTfndfirst_var(BATmirror(b),v);			} else {				p = SORTfndfirst_loc(BATmirror(b),v);			}		}		if (p) {			idx = *(ssize_t*) BUNtail(b,p);			if (idx && (p >= BUNlast(b) || ATOMcmp(b->htype, v, BUNhead(b, p)))) idx--;		}	}	*ret = (oid) idx;	return GDK_SUCCEED;}#line 1713 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/algebra.mx"intCMDmerge(BAT **ret, BAT *b){	int n = BATcount(b);	BAT *bn = *ret = BATnew(TYPE_lng, TYPE_void, n);	BUN p, q;	int xx;	lng *r = (lng *) BUNhead(bn, BUNfirst(bn));	BATloopFast(b, p, q, xx) {		oid hp = *(oid *) BUNhead(b, p);		oid tp = *(oid *) BUNtail(b, p);		*r++ = (((lng) hp) << 32) + tp;	}	bn->batBuns->free = (BUN) r - bn->batBuns->base;	BATsetcount(bn, bn->batBuns->free/BUNsize(bn));	if (!bn->batDirty)		bn->batDirty = TRUE;	bn->hsorted = ( BAThordered(b)&1 && (BATtordered(b)&1 || BAThkey(b))) 		? GDK_SORTED : FALSE ;	bn->tsorted = FALSE ;	bn->tdense = FALSE ;	BATkey(bn, BAThkey(b) || BATtkey(b)) ;	BATkey(BATmirror(bn), FALSE) ;	return GDK_SUCCEED;}intCMDsplit(BAT **ret, BAT *b){	int n = BATcount(b);	BAT *bn = *ret = BATnew(TYPE_oid, TYPE_oid, n);	int i;	lng *r = (lng *) BUNhead(b, BUNfirst(b));	for (i = 0; i < n; i++, r++) {		oid hp = (int) (*r >> 32);		oid tp = (int) *r;		bunfastins(bn, &hp, &tp);	}	bn->hsorted = BAThordered(b)&1 ? GDK_SORTED : FALSE ;	bn->tsorted = FALSE ;	bn->hdense = FALSE ;	bn->tdense = FALSE ;	BATkey(bn, FALSE) ;	BATkey(BATmirror(bn), FALSE) ;	return GDK_SUCCEED;bunins_failed:	BBPreclaim(bn);	return GDK_FAIL;}#line 1808 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/algebra.mx"#line 1784 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/algebra.mx"algebra_export str ALGsum_sht_sht(sht* res, int *bid) ;str ALGsum_sht_sht(sht* res, int *bid) {	BAT *b;	if( (b= BATdescriptor(*bid)) == NULL ){		 throw(MAL, "algebra.sum", "Cannot access descriptor");	}	CMDsum_sht_sht(res,b);	BBPreleaseref(b->batCacheid);	return MAL_SUCCEED;}#line 1809 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/algebra.mx"#line 1784 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/algebra.mx"algebra_export str ALGsum_sht_int(int* res, int *bid) ;str ALGsum_sht_int(int* res, int *bid) {	BAT *b;	if( (b= BATdescriptor(*bid)) == NULL ){		 throw(MAL, "algebra.sum", "Cannot access descriptor");	}	CMDsum_sht_int(res,b);	BBPreleaseref(b->batCacheid);	return MAL_SUCCEED;}#line 1810 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/algebra.

⌨️ 快捷键说明

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