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

📄 gdk_batop.c

📁 这个是内存数据库中的一个管理工具
💻 C
📖 第 1 页 / 共 5 页
字号:
#line 44 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_batop.mx"#include "monetdb_config.h"#include "gdk.h"#include "gdk_scanselect.h"#line 64 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_batop.mx"#define bunins(b,h,t) if (BUNins(b,h,t,force) == NULL) return NULL;BAT *BATins(BAT *b, BAT *n, bit force){	BAT *tmp = NULL, *res = NULL;	ssize_t needed = 0;	int fastpath = 0;	int countonly = (b->htype == TYPE_void && b->ttype == TYPE_void);	if (b == NULL || n == NULL || BATcount(n) == 0) {		return b;	}	ALIGNins(b, "BATins", force);	BATcompatible(b, n);	if (b->htype != TYPE_void && (b->ttype == TYPE_void || (!b->hhash && b->thash && ATOMstorage(b->ttype) == TYPE_int))) {	/* OIDDEPEND */		return BATmirror(BATins(BATmirror(b), BATmirror(n), force));	}	if (b->htype == TYPE_void && b->hseqbase != oid_nil) {		oid t = *(oid *) BUNhead(b, BUNlast(b) - BUNsize(b));		oid h = *(oid *) BUNhead(n, BUNfirst(n));		if (BATcount(b) == 0 && (BATcount(n) == 1 || BAThdense(n))) {			b->hseqbase = h;			BATmirror(b)->tseqbase = h;		} else if ((t + 1) != h || !BAThdense(n)) {			b = BATmaterialize(b, BATcount(b) + BATcount(n));			countonly=0;			if (b == NULL)				return NULL;		}	}	if (b->ttype == TYPE_void && b->tseqbase != oid_nil) {		oid t = *(oid *) BUNtail(b, BUNlast(b) - BUNsize(b));		oid h = *(oid *) BUNtail(n, BUNfirst(n));		if (BATcount(b) == 0 && (BATcount(n) == 1 || BATtdense(n))) {			b->tseqbase = h;			BATmirror(b)->hseqbase = h;		} else if ((t + 1) != h || !BATtdense(n)) {			b = BATmaterializet(b, BATcount(b) + BATcount(n));			countonly=0;			if (b == NULL)				return NULL;		}	}	if (b->thash == NULL && b->batSet == 0 && (b->tkey & BOUND2BTRUE) == 0 && ((b->hkey & BOUND2BTRUE) == 0 || n->hkey) && (b->hhash == NULL || ATOMstorage(b->htype) == TYPE_int)) {		if ((b->hkey & BOUND2BTRUE)) {			tmp = n = BATkdiff(n, b);			if (n == NULL)				return NULL;		}		fastpath = 1;	}	needed = BATcount(n) - (((b)->batBuns->size - (b)->batBuns->free) / BUNsize(b));	if (needed > 0) {		/* if needed exceeds a normal growth extend just with needed */		size_t ncap = BATcapacity(b) + needed;		size_t grows = BATgrows(b);		if (ncap > grows)			grows = ncap;		if (BATextend(b, grows) == NULL)			fastpath = 0;	}	if (b->hhash == NULL && b->hkey & BOUND2BTRUE) {		BAThash(b, BATcount(b) + BATcount(n));	}	if (b->thash == NULL && b->tkey & BOUND2BTRUE) {		BAThash(BATmirror(b), BATcount(b) + BATcount(n));	}	b->batDirty = 1;	if (fastpath) {		BUN p, q, r = BUNlast(b);		int xx, yy = BUNsize(b);		if (BATcount(b) == 0) {			ALIGNset(b, n);		} else if (BATcount(n)) {			BUN last = BUNlast(b) - BUNsize(b);			size_t idx = BUNindex(b, BUNlast(b));			xx = ATOMcmp(b->htype, BUNhead(n, BUNfirst(n)), BUNhead(b, last));			if ((BAThordered(b) & 1) && ((BAThordered(n) & 1) == 0 || xx < 0)) {				b->hsorted = FALSE;				b->H->nosorted = idx;				if (b->hdense & 1) {					b->hdense = FALSE;					b->H->nodense = idx;				}			}			if ((BAThordered(b) == (bit)GDK_SORTED_REV) && ((BAThordered(n) != (bit)GDK_SORTED_REV) || xx > 0)) {				b->hsorted = FALSE;				b->H->nosorted_rev = idx;			}			if (b->hkey && (b->hkey & BOUND2BTRUE) == 0 && ((BAThordered(b) & 1) == 0 || n->hkey == 0 || xx == 0)) {	 /* StM: GDK_SORTED_REV ? */				BATkey(b, FALSE);			}			if (b->htype != TYPE_void && (b->hsorted & b->hdense & 1) && (BAThdense(n) == 0 || *(oid *) BUNhloc(b, last) != 1 + *(oid *) BUNhead(n, BUNfirst(n)))) {				b->hdense = FALSE;				b->H->nodense = idx;			}			xx = ATOMcmp(b->ttype, BUNtail(n, BUNfirst(n)), BUNtail(b, last));			if ((BATtordered(b) & 1) && ((BATtordered(n) & 1) == 0 || xx < 0)) {				b->tsorted = FALSE;				b->T->nosorted = idx;				if (b->tdense & 1) {					b->tdense = FALSE;					b->T->nodense = idx;				}			}			if ((BATtordered(b) == (bit)GDK_SORTED_REV) && ((BATtordered(n) != (bit)GDK_SORTED_REV) || xx > 0)) {				b->tsorted = FALSE;				b->T->nosorted_rev = idx;			}			if ((BATtordered(b) & 1) == 0 || n->tkey == 0 || xx == 0) {	/* StM: GDK_SORTED_REV ? */				if (b->tkey)					BATkey(BATmirror(b), FALSE);			}			if (b->ttype != TYPE_void && (b->tsorted & b->tdense & 1) && (BATtdense(n) == 0 || *(oid *) BUNtloc(b, last) != 1 + *(oid *) BUNtail(n, BUNfirst(n)))) {				b->tdense = FALSE;				b->T->nodense = idx;			}		}		if (countonly) { 			b->batBuns->free += n->batCount;			BATsetcount(b, b->batCount + n->batCount);		} else if (b->htype == TYPE_void) {			BATloopFast(n, p, q, xx) {				bunfastins_nocheck(b, r, NULL, BUNtail(n, p), yy);				r += yy;			}		} else if (b->hhash) {			size_t i = BUNindex(b, BUNlast(b));			BATloopFast(n, p, q, xx) {				ptr v = BUNhead(n, p);				bunfastins_nocheck(b, r, v, BUNtail(n, p), yy);				HASHins_int(b->hhash, (hash_t) i, v);				r += yy;				i++;			}		} else {			BATloopFast(n, p, q, xx) {				bunfastins_nocheck(b, r, BUNhead(n, p), BUNtail(n, p), yy);				r += yy;			}		}	} else {		#line 49 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_batop.mx"{	BUN p1, p2;	int xx;	BATloopFast(n, p1, p2, xx) {		bunins(b, BUNhead(n, p1), BUNtail(n, p1));	}}#line 218 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_batop.mx"	}	res = b;      bunins_failed:	if (tmp)		BBPreclaim(tmp);	return res;}BAT*BATappend(BAT *b, BAT *n, bit force){	ssize_t sz = BATcount(n);	ssize_t needed = 0;	int fastpath = 1;	int countonly = (b->htype == TYPE_void && b->ttype == TYPE_void);	if (b == NULL || n == NULL || sz == 0) {		return b;	}	ALIGNapp(b, "BATappend", force);	BATcompatible(b, n);	b->batDirty = 1;	needed = sz - (((b)->batBuns->size - (b)->batBuns->free) / BUNsize(b));	if (!countonly && needed > 0) {		/* if needed exceeds a normal growth extend just with needed */		size_t ncap = BATcapacity(b) + needed;		size_t grows = BATgrows(b);		if (ncap > grows)			grows = ncap;		if (BATextend(b, grows) == NULL)			fastpath = 0;	}	/* append two void,void bats */	if (b->ttype == TYPE_void && BATtdense(b)) { 		oid f = n->tseqbase;		if (b->ttype != TYPE_void)			f = *(oid*)BUNtloc(n, BUNfirst(n)); 		if (BATcount(b) == 0 && f != oid_nil)			BATseqbase(BATmirror(b), f);		if (BATtdense(n) && BATcount(b) + b->tseqbase == f) {			if (b->htype != TYPE_void) {				BUN r = BUNlast(b);				int yy = BUNsize(b);				oid m;				f = MAXoid(b);				f++;				m = f + sz;				for(; f<m; f++, r+= yy) {					bunfastins_nocheck(b, r, (ptr)&f, NULL, yy);				}			} else {				sz += BATcount(b);				BATsetcount(b, sz);				b->batBuns->free = sz*BUNsize(b);			}			return b;		}		/* we need to materialize the tail */ 		BATmaterializet(b, BATcount(b)+sz);	}	/* a hash is useless for void bats */		if (b->hhash) 		HASHremove(b);	if (b->thash && (2* b->thash->mask) < (BATcount(b)+sz)) {		HASHremove(BATmirror(b));	}	if (!(b->thash == NULL && b->batSet == 0 && (b->tkey & BOUND2BTRUE) == 0 && (b->hhash == NULL || ATOMstorage(b->htype) == ATOMstorage(TYPE_oid)))) 		fastpath = 0;	if (fastpath) {		BUN p, q, r = BUNlast(b);		int xx, yy = BUNsize(b);		if (BATcount(b) == 0) {			BAT *bm = BATmirror(b);			ALIGNsetH(bm, BATmirror(n));			b->tseqbase = bm->hseqbase = n->tseqbase;			if (n->tdense && n->ttype == TYPE_oid) {				b->tseqbase = bm->hseqbase = *(oid*)BUNtail(n, BUNfirst(n));			}			b->tdense = bm->hdense = n->tdense;			b->T->nodense = bm->H->nodense = n->T->nodense;			b->tkey = bm->hkey |= (n->tkey & TRUE);			b->T->nokey[0] = bm->H->nokey[0] = n->T->nokey[0];			b->T->nokey[1] = bm->H->nokey[1] = n->T->nokey[1];		} else {			BUN last = BUNlast(b) - BUNsize(b);			size_t idx = BUNindex(b, BUNlast(b));			xx = ATOMcmp(b->ttype, BUNtail(n, BUNfirst(n)), BUNtail(b, last));			if ((BATtordered(b) & 1) && ((BATtordered(n) & 1) == 0 || xx < 0)) {				b->tsorted = FALSE;				b->T->nosorted = idx;				if (b->tdense & 1) {					b->tdense = FALSE;					b->T->nodense = idx;				}			}			if ((BATtordered(b) == (bit)GDK_SORTED_REV) && ((BATtordered(n) != (bit)GDK_SORTED_REV) || xx > 0)) {				b->tsorted = FALSE;				b->T->nosorted_rev = idx;			}			if ((BATtordered(b) & 1) == 0 || n->tkey == 0 || xx == 0) {	/* StM: GDK_SORTED_REV ? */				if (b->tkey)					BATkey(BATmirror(b), FALSE);			}			if (b->ttype != TYPE_void && (b->tsorted & b->tdense & 1) && (BATtdense(n) == 0 || *(oid *) BUNtloc(b, last) != 1 + *(oid *) BUNtail(n, BUNfirst(n)))) {				b->tdense = FALSE;				b->T->nodense = idx;			}		}		if (b->htype == TYPE_void) {			BATloopFast(n, p, q, xx) {				bunfastins_nocheck(b, r, NULL, BUNtail(n, p), yy);				r += yy;			}		} else {			oid o = MAXoid(b);			o++;			BATloopFast(n, p, q, xx) {				bunfastins_nocheck(b, r, &o, BUNtail(n, p), yy);				o++;				r += yy;			}		}	} else {		BUN p, q;		int xx;		size_t i = BUNindex(b, BUNlast(b));		BAT *bm = BBP_cache(-b->batCacheid);		if (b->tkey & BOUND2BTRUE) {			b->tdense = b->tsorted = 0;			if (b->hseqbase != oid_nil) {				oid h = b->hseqbase + i;				BATloopFast(n, p, q, xx) {					ptr t = BUNtail(n, p);					if (!BUNfnd(bm, t)) { 						bunfastins(b ,&h, t);						if (b->thash) {							HASHins(bm, (hash_t) i, t);						}						h++;						i++;					}				}			} else {				oid on = oid_nil;					BATloopFast(n, p, q, xx) {					ptr t = BUNtail(n, p);					if (!BUNfnd(bm, t)) {						bunfastins(b ,&on, t);						if (b->thash) {							HASHins(bm, (hash_t) i, t);						}						i++;					}				}				BATkey(b, FALSE);				b->hdense = b->hsorted = 0;			}		} else if (b->hseqbase != oid_nil) {			oid h = b->hseqbase + BATcount(b);			BATloopFast(n, p, q, xx) {				ptr t = BUNtail(n, p);				bunfastins(b ,&h, t);				if (b->thash) {					HASHins(bm, (hash_t) i, t);				}				i++;				h++;			}			BATkey(BATmirror(b), FALSE);			b->tdense = b->tsorted = 0;		} else {			oid on = oid_nil;			BATloopFast(n, p, q, xx) {				ptr t = BUNtail(n, p);				bunfastins(b ,&on, t);				if (b->thash) {					HASHins(bm, (hash_t) i, t);				}				i++;			}			BATkey(b, FALSE);			BATkey(BATmirror(b), FALSE);			b->hdense = b->hsorted = 0;			b->tdense = b->tsorted = 0;		}	}	return b;bunins_failed:	return NULL;}#define bundel(b,h,t) if (BUNdel(b,h,t,force) == NULL) return NULL;BAT *BATdel(BAT *b, BAT *n, bit force){	ERRORcheck(b == NULL, "set:BAT required\n");	ERRORcheck(n == NULL, "set:BAT required\n");	if (BATcount(n) == 0) {		return b;	}	ALIGNdel(b, "BATdel", force);	TYPEcheck(b->htype, n->htype);	TYPEcheck(b->ttype, n->ttype);	#line 49 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_batop.mx"{	BUN p1, p2;	int xx;	BATloopFast(n, p1, p2, xx) {		bundel(b, BUNhead(n, p1), BUNtail(n, p1));	}}#line 446 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_batop.mx"	return b;}#define bundelhead(b,h,t) if (BUNdelHead(b,h,force) == NULL) return NULL;BAT *BATdelHead(BAT *b, BAT *n, bit force){	ERRORcheck(b == NULL, "set:BAT required\n");	ERRORcheck(n == NULL, "set:BAT required\n");	if (BATcount(n) == 0) {		return b;	}	ALIGNdel(b, "BATdelHead", force);	TYPEcheck(b->htype, n->htype);	#line 49 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_batop.mx"{	BUN p1, p2;	int xx;	BATloopFast(n, p1, p2, xx) {		bundelhead(b, BUNhead(n, p1), BUNtail(n, p1));	}}#line 461 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_batop.mx"	return b;}#line 469 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_batop.mx"#define bunreplace(b,h,t) if (BUNreplace(b,h,0) == NULL) return NULL;BAT *BATreplace(BAT *b, BAT *n, bit force){	if (b == NULL || n == NULL || BATcount(n) == 0) {		return b;	}	BATcompatible(b, n);#define BUNreplace_force(a,b,c) BUNreplace(a,b,c,force)	#line 49 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_batop.mx"{	BUN p1, p2;	int xx;	BATloopFast(n, p1, p2, xx) {		BUNreplace_force(b, BUNhead(n, p1), BUNtail(n, p1));	}}#line 478 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_batop.mx"	return b;}#line 484 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_batop.mx"#line 509 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_batop.mx"BAT *BATslice(BAT *b, size_t l, size_t h){	size_t low = l;	int xx;	BAT *bn;	BATcheck(b, "BATslice");	if (h > BATcount(b))		h = BATcount(b);	if (h < l)		h = l;	l += BUNindex(b, BUNfirst(b));	h += BUNindex(b, BUNfirst(b));#line 528 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_batop.mx"	if (BATrestricted(b) == BAT_READ) {		bn = VIEWcreate_(b, TRUE);		bn->batBuns->base = BUNptr(b, l);		bn->batFirst = bn->batDeleted = bn->batInserted = bn->batBuns->base;		bn->batBuns->maxsize = bn->batBuns->size = bn->batBuns->free = BUNptr(b, h) - bn->batBuns->base;		BATsetcount(bn, bn->batBuns->free/BUNsize(bn));#line 537 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_batop.mx"	} else {		BUN p = BUNptr(b, l);		BUN q = BUNptr(b, h);		bn = BATnew(b->htype, b->ttype, h - l);		if (bn == NULL) {			return bn;		}		if (b->htype != b->ttype || b->htype != TYPE_void) {			for (xx = BUNsize(b); p < q; p += xx) {				bunfastins(bn, BUNhead(b, p), BUNtail(b, p));			}		} else {			BATsetcount(bn, h-l);			bn->batBuns->free = (h-l);		}	}	bn->hsorted = BAThordered(b);	bn->tsorted = BATtordered(b);

⌨️ 快捷键说明

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