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

📄 gdk_batop.c

📁 这个是内存数据库中的一个管理工具
💻 C
📖 第 1 页 / 共 5 页
字号:
	BATkey(bn, BAThkey(b));	BATkey(BATmirror(bn), BATtkey(b));	if (BAThdense(b)) {		bn->hdense = TRUE;		BATseqbase(bn, b->hseqbase + low);	} else if (bn->hkey && bn->htype == TYPE_oid) {		if (BATcount(bn) == 0) {			bn->hdense = TRUE;			BATseqbase(bn, 0);		} else if (* (oid *) BUNhloc(bn, BUNfirst(bn)) + BATcount(bn) - 1 == * (oid *) BUNhloc(bn, BUNlast(bn) - BUNsize(bn))) {			bn->hdense = TRUE;			BATseqbase(bn, * (oid *) BUNhloc(bn, BUNfirst(bn)));		}	}	if (BATtdense(b)) {		bn->tdense = TRUE;		BATseqbase(BATmirror(bn), b->tseqbase + low);	} else if (bn->tkey && bn->ttype == TYPE_oid) {		if (BATcount(bn) == 0) {			bn->tdense = TRUE;			BATseqbase(BATmirror(bn), 0);		} else if (* (oid *) BUNtloc(bn, BUNfirst(bn)) + BATcount(bn) - 1 == * (oid *) BUNtloc(bn, BUNlast(bn) - BUNsize(bn))) {			bn->tdense = TRUE;			BATseqbase(BATmirror(bn), * (oid *) BUNtloc(bn, BUNfirst(bn)));		}	}	return bn;      bunins_failed:	BBPreclaim(bn);	return NULL;}#line 672 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_batop.mx"static BAT *BAT_hashselect(BAT *b, BAT *bn, ptr tl){	int ht = bn->htype, tt = bn->ttype;	size_t size = BATcount(bn);	hash_t i;	BATcheck(b, "BAT_hashselect");	b= BATmirror(b);	if (BATprepareHash(b)) {	      bunins_failed:		BBPreclaim(bn);		return NULL;	}	while (bn) {		BUN p, q = BUNfirst(bn);		BUN r = (BUN) ((char *) Bunbase(bn) + bn->batBuns->size);		int bs = BUNsize(bn);		if (b->tvarsized) {			#line 622 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_batop.mx"	switch(ATOMstorage(b->htype)) {#ifndef NOEXPAND_CHR	case TYPE_chr:		#line 598 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_batop.mx"	HASHloop_chr(b, b->hhash, i, tl, p) {		if (q < r)			bunfastins_nocheck(bn, q, BUNtvar(b, p), tl, bs);		q += bs;	}#line 625 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_batop.mx"		break;#endif#ifndef NOEXPAND_BTE	case TYPE_bte:		#line 598 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_batop.mx"	HASHloop_bte(b, b->hhash, i, tl, p) {		if (q < r)			bunfastins_nocheck(bn, q, BUNtvar(b, p), tl, bs);		q += bs;	}#line 630 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_batop.mx"		break;#endif#ifndef NOEXPAND_SHT	case TYPE_sht:		#line 598 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_batop.mx"	HASHloop_sht(b, b->hhash, i, tl, p) {		if (q < r)			bunfastins_nocheck(bn, q, BUNtvar(b, p), tl, bs);		q += bs;	}#line 635 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_batop.mx"		break;#endif#ifndef NOEXPAND_INT	case TYPE_int:		#line 598 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_batop.mx"	HASHloop_int(b, b->hhash, i, tl, p) {		if (q < r)			bunfastins_nocheck(bn, q, BUNtvar(b, p), tl, bs);		q += bs;	}#line 640 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_batop.mx"		break;#endif#ifndef NOEXPAND_FLT	case TYPE_flt:		#line 598 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_batop.mx"	HASHloop_flt(b, b->hhash, i, tl, p) {		if (q < r)			bunfastins_nocheck(bn, q, BUNtvar(b, p), tl, bs);		q += bs;	}#line 645 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_batop.mx"		break;#endif#ifndef NOEXPAND_DBL	case TYPE_dbl:		#line 598 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_batop.mx"	HASHloop_dbl(b, b->hhash, i, tl, p) {		if (q < r)			bunfastins_nocheck(bn, q, BUNtvar(b, p), tl, bs);		q += bs;	}#line 650 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_batop.mx"		break;#endif#ifndef NOEXPAND_LNG	case TYPE_lng:		#line 598 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_batop.mx"	HASHloop_lng(b, b->hhash, i, tl, p) {		if (q < r)			bunfastins_nocheck(bn, q, BUNtvar(b, p), tl, bs);		q += bs;	}#line 655 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_batop.mx"		break;#endif#ifndef NOEXPAND_STR	case TYPE_str:		#line 604 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_batop.mx"	if (strElimDoubles(b->hheap)) {		size_t j;		HASHloop_fstr(b, b->hhash, i, j, tl) {			p = BUNptr(b, i);			if (q < r)				bunfastins_nocheck(bn, q, BUNtvar(b, p), tl, bs);			q += bs;		}	} else {		HASHloop_str(b, b->hhash, i, tl) {			p = BUNptr(b, i);			if (q < r)				bunfastins_nocheck(bn, q, BUNtvar(b, p), tl, bs);			q += bs;		}	}#line 660 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_batop.mx"		break;#endif	default:		if (b->hvarsized) {			#line 598 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_batop.mx"	HASHloopvar(b, b->hhash, i, tl, p) {		if (q < r)			bunfastins_nocheck(bn, q, BUNtvar(b, p), tl, bs);		q += bs;	}#line 665 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_batop.mx"		} else {			#line 598 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_batop.mx"	HASHlooploc(b, b->hhash, i, tl, p) {		if (q < r)			bunfastins_nocheck(bn, q, BUNtvar(b, p), tl, bs);		q += bs;	}#line 667 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_batop.mx"		}		break;	}#line 692 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_batop.mx"		} else {			#line 622 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_batop.mx"	switch(ATOMstorage(b->htype)) {#ifndef NOEXPAND_CHR	case TYPE_chr:		#line 598 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_batop.mx"	HASHloop_chr(b, b->hhash, i, tl, p) {		if (q < r)			bunfastins_nocheck(bn, q, BUNtloc(b, p), tl, bs);		q += bs;	}#line 625 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_batop.mx"		break;#endif#ifndef NOEXPAND_BTE	case TYPE_bte:		#line 598 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_batop.mx"	HASHloop_bte(b, b->hhash, i, tl, p) {		if (q < r)			bunfastins_nocheck(bn, q, BUNtloc(b, p), tl, bs);		q += bs;	}#line 630 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_batop.mx"		break;#endif#ifndef NOEXPAND_SHT	case TYPE_sht:		#line 598 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_batop.mx"	HASHloop_sht(b, b->hhash, i, tl, p) {		if (q < r)			bunfastins_nocheck(bn, q, BUNtloc(b, p), tl, bs);		q += bs;	}#line 635 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_batop.mx"		break;#endif#ifndef NOEXPAND_INT	case TYPE_int:		#line 598 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_batop.mx"	HASHloop_int(b, b->hhash, i, tl, p) {		if (q < r)			bunfastins_nocheck(bn, q, BUNtloc(b, p), tl, bs);		q += bs;	}#line 640 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_batop.mx"		break;#endif#ifndef NOEXPAND_FLT	case TYPE_flt:		#line 598 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_batop.mx"	HASHloop_flt(b, b->hhash, i, tl, p) {		if (q < r)			bunfastins_nocheck(bn, q, BUNtloc(b, p), tl, bs);		q += bs;	}#line 645 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_batop.mx"		break;#endif#ifndef NOEXPAND_DBL	case TYPE_dbl:		#line 598 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_batop.mx"	HASHloop_dbl(b, b->hhash, i, tl, p) {		if (q < r)			bunfastins_nocheck(bn, q, BUNtloc(b, p), tl, bs);		q += bs;	}#line 650 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_batop.mx"		break;#endif#ifndef NOEXPAND_LNG	case TYPE_lng:		#line 598 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_batop.mx"	HASHloop_lng(b, b->hhash, i, tl, p) {		if (q < r)			bunfastins_nocheck(bn, q, BUNtloc(b, p), tl, bs);		q += bs;	}#line 655 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_batop.mx"		break;#endif#ifndef NOEXPAND_STR	case TYPE_str:		#line 604 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_batop.mx"	if (strElimDoubles(b->hheap)) {		size_t j;		HASHloop_fstr(b, b->hhash, i, j, tl) {			p = BUNptr(b, i);			if (q < r)				bunfastins_nocheck(bn, q, BUNtloc(b, p), tl, bs);			q += bs;		}	} else {		HASHloop_str(b, b->hhash, i, tl) {			p = BUNptr(b, i);			if (q < r)				bunfastins_nocheck(bn, q, BUNtloc(b, p), tl, bs);			q += bs;		}	}#line 660 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_batop.mx"		break;#endif	default:		if (b->hvarsized) {			#line 598 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_batop.mx"	HASHloopvar(b, b->hhash, i, tl, p) {		if (q < r)			bunfastins_nocheck(bn, q, BUNtloc(b, p), tl, bs);		q += bs;	}#line 665 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_batop.mx"		} else {			#line 598 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_batop.mx"	HASHlooploc(b, b->hhash, i, tl, p) {		if (q < r)			bunfastins_nocheck(bn, q, BUNtloc(b, p), tl, bs);		q += bs;	}#line 667 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_batop.mx"		}		break;	}#line 694 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_batop.mx"		}		if (q <= r)			break;		size = (q - BUNfirst(bn)) / bs;		BBPreclaim(bn);		bn = BATnew(ht, tt, size);	}	return bn;}#line 707 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_batop.mx"#line 720 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_batop.mx"BAT *BAT_select_(BAT *b, ptr tl, ptr th, bit li, bit hi, bit tail, bit preserve_order){	int hval, lval, equi, t, ht, tt;	size_t offset, batcnt, estimate = 0;	ptr nil;	BAT *bn;	BUN p, q;	BATcheck(b, "BATselect: \n");	BATcheck(tl, "BATselect: tl value required\n");#line 734 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_batop.mx"	batcnt = BATcount(b);	t = b->ttype;	nil = ATOMnilptr(t);	lval = ATOMcmp(t, tl, nil) || (th == NULL);	equi = ((th == NULL) || (lval && !ATOMcmp(t, tl, th)));	if (equi) {		if (th == NULL)			hi = li;		th = tl;		hval = 1;	/* equi-select */	} else {		hval = ATOMcmp(t, th, nil);	}	/* preliminarily determine result types */	ht = BAThtype(b);	tt = tail ? BATttype(b) : TYPE_void;	if (hval && ((ATOMcmp(t, tl, th) > 0) || (equi && !(li && hi)))) {		/* empty range */		ALGODEBUG THRprintf(GDKout, "#BAT_select_(b=%s): empty range;\n", BATgetId(b));		return BATnew(ht, tt, 10);	}#line 760 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_batop.mx"#line 766 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_batop.mx"	if (BATtordered(b) & 1) {		BAT *v = tail ? b : VIEWhead_(b, b->batRestricted);		size_t high = batcnt;		size_t low = 0;		if (BATtdense(b)) {			/* Selections on voids are positional. */			if (hval) {				size_t h = (*(oid *) th) + (hi ? 1 : 0);				if (h > b->tseqbase)					h -= b->tseqbase;				else					h = 0;				if (h < high)					high = h;			}			if (lval) {			    if (*(oid *)tl != oid_nil) {				size_t l = (*(oid *) tl) + (li ? 0 : 1);				if (l > b->tseqbase)					l -= b->tseqbase;				else					l = 0;				if (l > low)					low = l;			    } else {			    	if (equi) {			    		/* nil-equi select on dense columns is empty */			    		high = low;			    	}			    }			}		} else {			/* Use probe-based binary search */			offset = BUNindex(b, BUNfirst(b));			if (lval) {				if (li)					p = SORTfndfirst(b, tl);				else					p = SORTfndlast(b, tl);			} else {				/* No lower bound, we must still exclude nils. They are in				 * front, so we can still slice, by starting after them.				 */				p = SORTfndlast(b, nil);			}			low = BUNindex(b, p);			if (low > offset)				low -= offset;			else				low = 0;			if (hval) {				if (hi)					q = SORTfndlast(b, th);				else					q = SORTfndfirst(b, th);				high = BUNindex(b, q);				if (high > offset)					high -= offset;				else					high = 0;			}		}		ALGODEBUG THRprintf(GDKout, "#BAT_select_(b=%s): BATslice(v=%s, low=" SZFMT ", high=" SZFMT ");\n", BATgetId(b), BATgetId(v), low, high);		bn = BATslice(v, low, high);		if (!tail) {			BBPreclaim(v);		}		return bn;	}#line 843 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_batop.mx"	if (BATtkey(b)) {		estimate = 1;	} else if (batcnt > 100000) {

⌨️ 快捷键说明

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