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

📄 gdk_bat.c

📁 这个是内存数据库中的一个管理工具
💻 C
📖 第 1 页 / 共 5 页
字号:
			    ATOMalign(t1) != ATOMalign(t2) ||			    BATatoms[t1].atomFix ||  			    BATatoms[t2].atomFix) return TRUE;		}	}	return FALSE;}#line 653 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_bat.mx"BAT *BATcopy(BAT *b, int ht, int tt, int writeable){	ssize_t bunstocopy = -1;	size_t cnt;	BAT *bn = NULL;	BATcheck(b, "BATcopy");	cnt = BATcount(b);	/* maybe a bit ugly to change the requested bat types?? */	if (b->htype == TYPE_void && !writeable) ht = TYPE_void;	if (b->ttype == TYPE_void && !writeable) tt = TYPE_void;	if (ht != b->htype && wrongtype(ht, b->htype)) {		GDKerror("BATcopy: wrong head-type requested\n");		return NULL;	}	if (tt != b->ttype && wrongtype(tt, b->ttype)) {		GDKerror("BATcopy: wrong tail-type requested\n");		return NULL;	}	/* first try case (1); create a view, possibly with different atom-types */	if (BATrestricted(b) == BAT_READ && !writeable) {		bn = VIEWcreate(b); 		if (bn == NULL) return NULL;		if (ht != bn->htype) {			BAT *bm = BATmirror(bn);			bn->htype = bm->ttype = ht;			bn->hvarsized = bm->tvarsized = ATOMvarsized(ht);                	bn->hseqbase = bm->tseqbase = b->hseqbase;		}		if (tt != bn->ttype) {			BAT *bm = BATmirror(bn);			bn->ttype = bm->htype = tt;			bn->tvarsized = bm->hvarsized = ATOMvarsized(tt);                	bn->tseqbase = bm->hseqbase = b->tseqbase;		}	} else { 		/* check whether we need case (4); BUN-by-BUN copy (by setting bunstocopy >=0) */		if (ATOMsize(ht) != ATOMsize(b->htype) ||		    ATOMsize(tt) != ATOMsize(b->ttype)) /* oops, void materialization */		{			bunstocopy = cnt;		} else if (BATatoms[ht].atomFix || BATatoms[tt].atomFix) { /* oops, we need to fix/unfix atoms */			bunstocopy = cnt;		} else if (VIEWparent(b)) {			/* extra checks needed for views */			BAT *p = BBP_cache(VIEWparent(b));			if (b->hloc == b->tloc || /* oops, mirror view! */			    ATOMsize(ht) != ATOMsize(p->htype) ||			    ATOMsize(tt) != ATOMsize(p->ttype) || /* oops, parent BUN layout was different */		            (ht == TYPE_void) != (p->htype == TYPE_void) ||		            (tt == TYPE_void) != (b->ttype == TYPE_void) || /* oops, BUN layout changes */			    BATcount(p) > cnt+cnt) /* reduced slice view: do not copy too much garbage */ 			{				bunstocopy = cnt;			}		}		bn = BATnew(ht, tt, MAX(1,bunstocopy));		if (bn == NULL) return NULL;		if (ht == TYPE_void && tt == TYPE_void) {			/* case (2): a void,void result => nothing to copy! */			bn->batBuns->free = cnt*BUNsize(bn);		} else if (bunstocopy < 0) {			/* case (3): just copy the heaps; if possible with copy-on-write VM support */			int remap = (writeable == 2) && (BATrestricted(b) != BAT_WRITE);			int hremap = remap && (ATOMstorage(ht) == TYPE_str) && !GDK_ELIMDOUBLES(b->hheap);			int tremap = remap && (ATOMstorage(tt) == TYPE_str) && !GDK_ELIMDOUBLES(b->theap);			Heap hp, hhp, thp;			memset(&hp, 0, sizeof(Heap));			memset(&hhp, 0, sizeof(Heap));			memset(&thp, 0, sizeof(Heap));			if ((heapcopy(&hp, b->batBuns, &remap) < 0) || 			    (bn->hheap && heapcopy(&hhp, b->hheap, &hremap) < 0) ||			    (bn->theap && heapcopy(&thp, b->theap, &tremap) < 0))			{				if (hhp.base) HEAPfree(&hhp);				if (hp.base) HEAPfree(&hp);				BBPreclaim(bn);				return NULL;			}			/* succeeded; replace dummy small heaps by the real ones */			DELTAsave(bn);			heapfree(bn->batBuns, &hp);			if (bn->hheap) heapfree(bn->hheap, &hhp);			if (bn->theap) heapfree(bn->theap, &thp); 			DELTAload(bn);			/* hloc/tloc must be as in src BUN heap */			if (bn->hloc != b->hloc || bn->tloc != b->tloc) {				BAT *bm = BATmirror(bn);				bn->hloc = bm->tloc = b->hloc;				bn->tloc = bm->hloc = b->tloc;			}			/* first/inserted must point equally far into the heap as in the source */			bn->batFirst = Bunbase(bn) + (b->batFirst - Bunbase(b));			bn->batInserted = Bunbase(bn) + (b->batInserted - Bunbase(b));			/* if we have copy-on-write heaps, bn is a logical view on b to ensure the heaps stay stable */			if (remap || hremap || tremap) {				bn->batLview = TRUE;				BBPshare(bn->batParentid = ABS(b->batCacheid));			}		} else if (BATatoms[ht].atomFix || BATatoms[tt].atomFix || (ht && tt) || ATOMstorage(MAX(ht,tt)) >= TYPE_str) {			/* case (4): one-by-one BUN insert (really slow) */			BUN p, q, r = BUNfirst(bn);			int xx, yy = BUNsize(bn);			BATloopFast(b, p, q, xx) {				ptr h = BUNhead(b, p);				ptr t = BUNtail(b, p);				bunfastins_nocheck(bn, r, h, t, yy);				r += yy;			}		} else if ((ht && b->htype == TYPE_void) || (tt && b->ttype == TYPE_void)) { 			/* case (4): optimized for unary void materialization */			oid cur = ht?b->hseqbase:b->tseqbase, *dst = (oid*) BUNfirst(bn);			oid inc = (cur != oid_nil);			bn->batBuns->free = bunstocopy*sizeof(oid);			while(bunstocopy--) { *dst++ = cur; cur += inc; }		} else {			/* case (4): optimized for simple array copy */			int tpe = ATOMstorage(ht|tt);			BUN cur = ht?BUNhloc(b, BUNfirst(b)):BUNtloc(b,BUNfirst(b));			int inc = BUNsize(b)/ATOMsize(tpe);			bn->batBuns->free = bunstocopy*ATOMsize(tpe);  			if (tpe == TYPE_chr || tpe == TYPE_bte) {				bte *src = (bte*) cur, *dst = (bte*) BUNfirst(bn);				while(bunstocopy--) { *dst++ = *src; src += inc; }			} else if (tpe == TYPE_sht) {				sht *src = (sht*) cur, *dst = (sht*) BUNfirst(bn);				while(bunstocopy--) { *dst++ = *src; src += inc; }			} else if ((tpe == TYPE_int) || (tpe == TYPE_flt)) {				int *src = (int*) cur, *dst = (int*) BUNfirst(bn);				while(bunstocopy--) { *dst++ = *src; src += inc; }			} else {				lng *src = (lng*) cur, *dst = (lng*) BUNfirst(bn);				while(bunstocopy--) { *dst++ = *src; src += inc; }			}		}		/* copy all properties (size+other) from the source bat */		BATsetcount(bn, cnt);	}	/* set properties (note that types may have changed in the copy) */		if (ATOMtype(ht) == ATOMtype(b->htype)) {		ALIGNsetH(bn, b); 	} else if (ATOMtype(ATOMstorage(ht)) == ATOMtype(ATOMstorage(b->htype))) {		bn->hsorted = b->hsorted; 		bn->hdense = b->hdense; 		if (b->hkey) BATkey(bn, TRUE);	} else {		bn->hsorted = bn->hdense = 0;	}	if (ATOMtype(tt) == ATOMtype(b->ttype)) {		ALIGNsetT(bn, b); 	} else if (ATOMtype(ATOMstorage(tt)) == ATOMtype(ATOMstorage(b->ttype))) {		bn->tsorted = b->tsorted;		bn->tdense = b->tdense;		if (b->tkey) BATkey(BATmirror(bn), TRUE);	} else { 		bn->tsorted = bn->tdense = 0;	}	if (writeable != TRUE) bn->batRestricted = BAT_READ;	return bn;  bunins_failed:	BBPreclaim(bn);	return NULL;}#line 889 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_bat.mx"BAT *BUNfastins(BAT *b, ptr h, ptr t){	bunfastins(b, h, t);	if (!b->batDirty)		b->batDirty = TRUE;	return b;      bunins_failed:	return NULL;}#line 906 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_bat.mx"#line 926 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_bat.mx"BAT *BUNins(BAT *b, ptr h, ptr t, bit force){	int countonly = (b->htype == TYPE_void && b->ttype == TYPE_void);	BUN p;	BAT *bm;	BATcheck(b, "BUNins");	BATcheck(h, "BUNins: head value is nil\n");	bm = BBP_cache(-b->batCacheid);	#line 907 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_bat.mx"	if ((h) && b->htype == TYPE_void && b->hseqbase != oid_nil) {		if (*(oid*) h != oid_nil) {			if (BATcount(b) == 0) {				b->hseqbase = *(oid*) h;				bm->tseqbase = *(oid*) h;			} else if (*(oid*) h != (b->hseqbase + BUNgetpos(b, BUNlast(b)))) {		 		b = BATmaterializeh(b, (size_t) ((double)BATcount(b)*1.2));				countonly=0;				if (b == NULL)					return b;			}		} else { 		 	b = BATmaterializeh(b, (size_t) ((double)BATcount(b)*1.2));			countonly=0;			if (b == NULL)				return b;		}	}#line 937 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_bat.mx"	#line 907 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_bat.mx"	if ((t) && b->ttype == TYPE_void && b->tseqbase != oid_nil) {		if (*(oid*) t != oid_nil) {			if (BATcount(b) == 0) {				b->tseqbase = *(oid*) t;				bm->hseqbase = *(oid*) t;			} else if (*(oid*) t != (b->tseqbase + BUNgetpos(b, BUNlast(b)))) {		 		b = BATmaterializet(b, (size_t) ((double)BATcount(b)*1.2));				countonly=0;				if (b == NULL)					return b;			}		} else { 		 	b = BATmaterializet(b, (size_t) ((double)BATcount(b)*1.2));			countonly=0;			if (b == NULL)				return b;		}	}#line 938 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_bat.mx"	if (b->batSet && BUNlocate(b, h, t)) {		return b;	}	if ((b->hkey & BOUND2BTRUE) && (p = BUNfnd(b, h))) {		if (BUNinplace(b, p, h, t, 0) == NULL)			return NULL;	} else if ((b->tkey & BOUND2BTRUE) && (p = BUNfnd(bm, t))) {		if (BUNinplace(bm, p, t, h, 0) == NULL)			return NULL;	} else {		size_t i;		size_t hsize = 0, tsize = 0;		if (b->hhash && b->hheap) hsize = b->hheap->size;		if (b->thash && b->theap) tsize = b->theap->size;		ALIGNins(b, "BUNins", force);		b->batDirty = 1;		p = BUNlast(b);	/* insert at end */		i = BUNindex(b, p);		if (p > b->batFirst) {			unsigned int bunsize = BUNsize(b);			if (b->htype != TYPE_void) {				int cmp = 0;				if (b->hsorted & 1) {					ptr prv = BUNhead(b, p - bunsize);					cmp = atom_CMP(h, prv, b->htype);					if (cmp < 0) {						b->H->nosorted = i;						b->hsorted = FALSE;					} else if (cmp && b->hdense && *(oid *) h != 1 + *(oid *) prv) {						b->H->nodense = i;						b->hdense = FALSE;					}					/* as nil < any, we only need to 					 * check on second BUNins if the 					 * first was nil */					if (i == 2 && cmp > 0) {	/* StM: i==1 ? */						int ht = b->htype;						cmp = atom_CMP(prv, ATOMnilptr(ht), ht);						if (cmp == 0) {							b->H->nosorted = 1;							b->hsorted = FALSE;						}					}				}				else if (b->hsorted == (bit)GDK_SORTED_REV) {					ptr prv = BUNhead(b, p - bunsize);					cmp = atom_CMP(h, prv, b->htype);					if (cmp > 0) {						b->H->nosorted_rev = i;						b->hsorted = FALSE;					}				}				if (b->hkey == TRUE && cmp <= 0) {					b->H->nokey[0] = i - 1;					b->H->nokey[1] = i;					b->hkey = bm->tkey = b->hdense = FALSE;				}			}			if (b->ttype != TYPE_void) {				int cmp = 0;				if (b->tsorted & 1) {					ptr prv = BUNtail(b, p - bunsize);					cmp = atom_CMP(t, prv, b->ttype);					if (cmp < 0) {						b->T->nosorted = i;						b->tsorted = FALSE;					} else if (cmp && b->tdense && *(oid *) t != 1 + *(oid *) prv) {						b->T->nodense = i;						b->tdense = FALSE;					}					/* as nil < any, we only need to 					 * check on second BUNins if the 					 * first was nil */					if (i == 2 && cmp > 0) {	/* StM: i==1 ? */						int tt = b->ttype;						cmp = atom_CMP(prv, ATOMnilptr(tt), tt);						if (cmp == 0) {							b->T->nosorted = 1;							b->tsorted = FALSE;						}					}				}				else if (b->tsorted == (bit)GDK_SORTED_REV) {					ptr prv = BUNtail(b, p - bunsize);					cmp = atom_CMP(t, prv, b->ttype);					if (cmp > 0) {						b->T->nosorted_rev = i;						b->tsorted = FALSE;					}				}				if (b->tkey == TRUE && cmp <= 0) {					b->T->nokey[0] = i - 1;					b->T->nokey[1] = i;					b->tkey = bm->hkey = b->tdense = FALSE;				}			}		} else {			if (b->htype == TYPE_oid) {				b->hkey = bm->tkey |= b->hdense = TRUE;				b->hseqbase = bm->tseqbase = *(oid *) h;			} else if (b->htype) {				b->hkey = bm->tkey |= TRUE;			}			if (b->ttype == TYPE_oid) {				b->tkey = bm->hkey |= b->tdense = TRUE;				b->tseqbase = bm->hseqbase = *(oid *) t;			} else if (b->ttype) {				b->tkey = bm->hkey |= TRUE;			}		}		if (!countonly) {			bunfastins(b, h, t);		} else { 			b->batBuns->free += 1;			BATsetcount(b, b->batCount+1);		}		/* first adapt the hashes; then the user-defined accelerators.		 * REASON: some accelerator updates (qsignature) use the hashes! 		 */		if (b->hhash) {			HASHins(b, (hash_t) i, h);			if (hsize && hsize != b->hheap->size) HEAPwarm(b->hheap);		}		if (b->thash) {			HASHins(bm, (hash_t) i, t);			if (tsize && tsize != b->theap->size) HEAPwarm(b->theap);		}	}	return b;      bunins_failed:	return NULL;}oid MAXoid(BAT *i){        oid o = i->hseqbase-1;        if (BATcount(i))                o = *(oid *) BUNhead(i, BUNlast(i) - BUNsize(i));        if (!BAThordered(i)) {                BUN r, s;                int d;                BATloopFast(i, r, s, d) {                        oid v = *(oid *) BUNhead(i, r);                        if (v > o)                                o = v;                }        }        return o;}#line 1106 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_bat.mx"BAT *BUNappend(BAT *b, ptr t, bit force){	size_t i;	BUN p;	BAT *bm;	ptr h = NULL;	oid id = 0;	int countonly;	size_t hsize = 0, tsize = 0;	if (b->hhash && b->hheap) hsize = b->hheap->size;	if (b->thash && b->theap) tsize = b->theap->size;	BATcheck(b, "BUNappend");	bm = BBP_cache(-b->batCacheid); 	countonly = (b->htype == TYPE_void && b->ttype == TYPE_void);	if (b->htype != TYPE_void && b->htype != TYPE_oid) {		GDKerror("BUNappend: can only append to void and oid bats\n");		return NULL;	}	ALIGNapp(b, "BUNappend", force);	b->batDirty = 1;	p = BUNlast(b);	/* insert at end */	i = BUNindex(b, p);	if ((b->tkey & BOUND2BTRUE) && BUNfnd(bm, t)) {		return b;	}	if (p > b->batFirst) {		unsigned int bunsize = BUNsize(b);		if (b->htype == TYPE_oid) {			h = &id;			id = MAXoid(b)+1;		}		if (b->ttype != TYPE_void) {			int cmp = 0;			if (b->tsorted & 1) {				ptr prv = BUNtail(b, p - bunsize);				cmp = atom_CMP(t, prv, b->ttype);				if (cmp < 0) {					b->T->nosorted = i;					b->tsorted = FALSE;				} else if (cmp && b->tdense && *(oid *) t != 1 + *(oid *) prv) {					b->T->nodense = i;					b->tdense = FALSE;				}				/* as nil < any, we only need to 				 * check on second BUNins if the 				 * first was nil */				if (i == 2 && cmp > 0) {	/* StM: i==1 ? */					int tt = b->ttype;					cmp = atom_CMP(prv, ATOMnilptr(tt), tt);					if (cmp == 0) {						b->T->nosorted = 1;						b->tsorted = FALSE;					}				}			} else if (b->tsorted == (bit)GDK_SORTED_REV) {				ptr prv = BUNtail(b, p - bunsize);				cmp = atom_CMP(t, prv, b->ttype);				if (cmp > 0) {					b->T->nosorted_rev = i;					b->tsorted = FALSE;				}			}			if (b->tkey == TRUE && cmp <= 0) {				b->T->nokey[0] = i - 1;				b->T->nokey[1] = i;				b->tkey = bm->hkey = b->tdense = FALSE;			}		} else if (b->tseqbase != oid_nil){ /* virtual ids */ 

⌨️ 快捷键说明

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