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

📄 group.c

📁 一个内存数据库的源代码这是服务器端还有客户端
💻 C
📖 第 1 页 / 共 5 页
字号:
	}#endif	bn->batBuns->free = ((BUN) dst) - bn->batBuns->base;	BATsetcount(bn, bn->batBuns->free/BUNsize(bn));	bn->tsorted = 0;	if (!(bn->batDirty&2)) bn = BATsetaccess(bn, BAT_READ);	ALIGNsetH(bn,b);	if (hash && !m)		GDKfree(hash);	return m ? NULL : map2histo(map);bunins_failed:	BBPreclaim(bn);	if (hash && !m)		GDKfree(hash);	return NULL;}#line 540 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/group.mx"/* Generate both 'normal' CTgroup and parameterized CTgroups */#line 545 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/group.mx"#line 549 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/group.mx"#line 554 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/group.mx"#define declare_mask_STANDARD	/* fixed */#define declare_mask_CUSTOM	hash_t mask = (1 << *N) - 1;intCTgroup(BAT **retval,		/* put pointer to BAT[oid,oid] record here. */	BAT **hbat,		/* put histogram BAT here */	BAT *b			/* pointer to BAT[oid,oid] record. */){	#line 591 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/group.mx"	BAT *histo = NULL, *bn = NULL;	declare_mask_STANDARD	/* b->tkey, simply return mirror(0), and hist = project(reverse(bn),1) */	if (b->tkey) {		int one = 1;		BAT *v = VIEWcombine(b);		bn = v;		if (b->batRestricted == BAT_WRITE) {			bn = BATcopy(v, v->htype, v->ttype, FALSE);			BBPreclaim(v);		}		histo = BATconst(BATmirror(bn), TYPE_int, &one);	} else {		bn = BATnew(b->htype, TYPE_oid, BATcount(b));		if (bn == NULL) {			return GDK_FAIL;		}		/* Poor man's clustered test: sorted & !keyed => clustered  */		if ( ((b->tsorted)&1) && !(b->tkey) ) {			#line 633 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/group.mx"	/* Choose appropriate clustered CTgroup implementation */	switch(tailtype(b,TRUE)) {	case TYPE_chr:		#line 552 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/group.mx"	histo =#line 636 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/group.mx" CTgroup_chr_clustered_STANDARD(b,bn,NULL);		break;	case TYPE_sht:		#line 552 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/group.mx"	histo =#line 639 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/group.mx" CTgroup_sht_clustered_STANDARD(b,bn,NULL);		break;	case TYPE_int:		#line 552 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/group.mx"	histo =#line 642 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/group.mx" CTgroup_int_clustered_STANDARD(b,bn,NULL);		break;	case TYPE_lng:		#line 552 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/group.mx"	histo =#line 645 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/group.mx" CTgroup_lng_clustered_STANDARD(b,bn,NULL);		break;	default:		#line 552 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/group.mx"	histo =#line 648 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/group.mx" CTgroup_any_clustered_STANDARD(b,bn,NULL);		break;	}#line 612 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/group.mx"		} else {			#line 633 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/group.mx"	/* Choose appropriate unclustered CTgroup implementation */	switch(tailtype(b,TRUE)) {	case TYPE_chr:		#line 552 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/group.mx"	histo =#line 636 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/group.mx" CTgroup_chr_unclustered_STANDARD(b,bn,NULL);		break;	case TYPE_sht:		#line 552 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/group.mx"	histo =#line 639 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/group.mx" CTgroup_sht_unclustered_STANDARD(b,bn,NULL);		break;	case TYPE_int:		#line 552 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/group.mx"	histo =#line 642 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/group.mx" CTgroup_int_unclustered_STANDARD(b,bn,NULL);		break;	case TYPE_lng:		#line 552 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/group.mx"	histo =#line 645 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/group.mx" CTgroup_lng_unclustered_STANDARD(b,bn,NULL);		break;	default:		#line 552 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/group.mx"	histo =#line 648 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/group.mx" CTgroup_any_unclustered_STANDARD(b,bn,NULL);		break;	}#line 614 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/group.mx"		}		if (histo == NULL) {			BBPreclaim(bn);			return GDK_FAIL;		}		bn->tsorted = 0;	}	if (BATcount(histo) == BATcount(bn)) {		BATkey(BATmirror(bn),TRUE);		BATkey(BATmirror(histo),TRUE);	}	ALIGNsetH(bn, b);	if (!(bn->batDirty&2)) bn = BATsetaccess(bn, BAT_READ);	*retval = bn;	*hbat = histo;	return grp_new(bn, histo);#line 563 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/group.mx"}intCTgroup_custom(BAT **retval,	/* put pointer to BAT[oid,oid] record here. */   BAT **hbat,	/* put histogram BAT here */   BAT *b,		/* pointer to BAT[oid,oid] record. */   int *N,		/* number of bits for hashmask */   int *rng		/* expected number of entries in map */){	#line 591 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/group.mx"	BAT *histo = NULL, *bn = NULL;	declare_mask_CUSTOM	/* b->tkey, simply return mirror(0), and hist = project(reverse(bn),1) */	if (b->tkey) {		int one = 1;		BAT *v = VIEWcombine(b);		bn = v;		if (b->batRestricted == BAT_WRITE) {			bn = BATcopy(v, v->htype, v->ttype, FALSE);			BBPreclaim(v);		}		histo = BATconst(BATmirror(bn), TYPE_int, &one);	} else {		bn = BATnew(b->htype, TYPE_oid, BATcount(b));		if (bn == NULL) {			return GDK_FAIL;		}		/* Poor man's clustered test: sorted & !keyed => clustered  */		if ( ((b->tsorted)&1) && !(b->tkey) ) {			#line 653 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/group.mx"	/* Choose appropriate clustered CTgroup implementation */	switch(tailtype(b,TRUE)) {	case TYPE_chr:		#line 552 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/group.mx"	histo =#line 656 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/group.mx" CTgroup_chr_clustered_CUSTOM(mask,*rng,b,bn,NULL);		break;	case TYPE_sht:		#line 552 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/group.mx"	histo =#line 659 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/group.mx" CTgroup_sht_clustered_CUSTOM(mask,*rng,b,bn,NULL);		break;	case TYPE_int:		#line 552 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/group.mx"	histo =#line 662 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/group.mx" CTgroup_int_clustered_CUSTOM(mask,*rng,b,bn,NULL);		break;	case TYPE_lng:		#line 552 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/group.mx"	histo =#line 665 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/group.mx" CTgroup_lng_clustered_CUSTOM(mask,*rng,b,bn,NULL);		break;	default:		#line 552 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/group.mx"	histo =#line 668 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/group.mx" CTgroup_any_clustered_CUSTOM(mask,*rng,b,bn,NULL);		break;	}#line 612 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/group.mx"		} else {			#line 653 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/group.mx"	/* Choose appropriate unclustered CTgroup implementation */	switch(tailtype(b,TRUE)) {	case TYPE_chr:		#line 552 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/group.mx"	histo =#line 656 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/group.mx" CTgroup_chr_unclustered_CUSTOM(mask,*rng,b,bn,NULL);		break;	case TYPE_sht:		#line 552 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/group.mx"	histo =#line 659 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/group.mx" CTgroup_sht_unclustered_CUSTOM(mask,*rng,b,bn,NULL);		break;	case TYPE_int:		#line 552 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/group.mx"	histo =#line 662 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/group.mx" CTgroup_int_unclustered_CUSTOM(mask,*rng,b,bn,NULL);		break;	case TYPE_lng:		#line 552 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/group.mx"	histo =#line 665 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/group.mx" CTgroup_lng_unclustered_CUSTOM(mask,*rng,b,bn,NULL);		break;	default:		#line 552 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/group.mx"	histo =#line 668 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/group.mx" CTgroup_any_unclustered_CUSTOM(mask,*rng,b,bn,NULL);		break;	}#line 614 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/group.mx"		}		if (histo == NULL) {			BBPreclaim(bn);			return GDK_FAIL;		}		bn->tsorted = 0;	}	if (BATcount(histo) == BATcount(bn)) {		BATkey(BATmirror(bn),TRUE);		BATkey(BATmirror(histo),TRUE);	}	ALIGNsetH(bn, b);	if (!(bn->batDirty&2)) bn = BATsetaccess(bn, BAT_READ);	*retval = bn;	*hbat = histo;	return grp_new(bn, histo);#line 574 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/group.mx"}static int bits(size_t i){	int sh;	assert(i>0);        for (sh = 0; i != 0; sh++) {                i >>= 1;        }	return sh;}#line 746 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/group.mx"/* Generate both 'normal' CTderive and clustered CTderive */#line 760 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/group.mx"#line 749 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/group.mx"#line 673 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/group.mx"BAT *CTderive_sync_chr_unclustered(BAT* ct_histo, BAT *ct_map, BAT *b, BAT *bn, map_T *m){	oid *dst = (oid*) BUNfirst(bn);	size_t yy = BUNsize(ct_map), zz, mapsize;	hash_t xx, *hash;	BUN p, q, r, cp = BUNfirst(ct_map) - yy;	mapentry_t entry, *e;	BAT *map;	int n = bits(BATcount(ct_histo)),*N = &n;	declare_simple	declare_mask_CUSTOM	int custom_rng = BATcount(ct_histo); /* expected number of groups */	hash_t custom_MASK = mask;	map_init_CUSTOM(map,hash,mask,entry,mapsize);	if (map == NULL)		return NULL;	/* core hash grouping algorithm */	BATloopFast(b, p, q, xx) {		ptr tcur = BUNtloc(b,p);		hash_t c;		oid hcur;		declare_unclustered		/* find corresponding value in 'ct_map' */		match_sync(ct_map, BUNhead(b,p), cp);		hcur = *(oid*) BUNtloc(ct_map,cp);		/* hash-lookup of [hcur,tcur] in map */		c = (((hash_t) hcur) ^ HASH_chr(tcur));		c = mix_int(c) & mask;		chain_unclustered {			r = BUNptr(map,zz);			e = (mapentry_t*) BUNhloc(map,r);			if (tst_derive_unclustered(simple_EQ, BUNtloc(map,r), chr)) {				if (m == NULL)					e->cnt++;				goto found;			}		}		/* not found-> insert new element in map (and hash) */		if (m) {			zz = mapsize;		} else {			entry.gid = *(oid*) BUNhead(b,p);		}		entry.hcur = hcur;		entry.link =  hash[c];		hash[c] = mapsize++;		bunfastins(map, &entry, tcur);		e = &entry;found:		/* ultra-fast 'insert' of [oid,gid] into result ct */		if (bn->htype)			*dst++ = *(oid*) BUNhead(b,p);		*dst++ = m?zz:e->gid;	}	bn->batBuns->free = ((BUN) dst) - bn->batBuns->base;	BATsetcount(bn, bn->batBuns->free/BUNsize(bn));	if (hash && !m)		GDKfree(hash);	if (!(bn->batDirty&2)) bn = BATsetaccess(bn, BAT_READ);	return m?NULL:map2histo(map);bunins_failed:	if (hash && !m)		GDKfree(hash);	BBPreclaim(bn);	return NULL;}#line 749 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/group.mx"#line 673 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/group.mx"BAT *CTderive_sync_sht_unclustered(BAT* ct_histo, BAT *ct_map, BAT *b, BAT *bn, map_T *m){	oid *dst = (oid*) BUNfirst(bn);	size_t yy = BUNsize(ct_map), zz, mapsize;	hash_t xx, *hash;	BUN p, q, r, cp = BUNfirst(ct_map) - yy;	mapentry_t entry, *e;	BAT *map;	int n = bits(BATcount(ct_histo)),*N = &n;	declare_simple	declare_mask_CUSTOM	int custom_rng = BATcount(ct_histo); /* expected number of groups */	hash_t custom_MASK = mask;	map_init_CUSTOM(map,hash,mask,entry,mapsize);	if (map == NULL)		return NULL;	/* core hash grouping algorithm */	BATloopFast(b, p, q, xx) {		ptr tcur = BUNtloc(b,p);		hash_t c;		oid hcur;		declare_unclustered		/* find corresponding value in 'ct_map' */		match_sync(ct_map, BUNhead(b,p), cp);		hcur = *(oid*) BUNtloc(ct_map,cp);		/* hash-lookup of [hcur,tcur] in map */		c = (((hash_t) hcur) ^ HASH_sht(tcur));		c = mix_int(c) & mask;		chain_unclustered {			r = BUNptr(map,zz);			e = (mapentry_t*) BUNhloc(map,r);			if (tst_derive_unclustered(simple_EQ, BUNtloc(map,r), sht)) {				if (m == NULL)					e->cnt++;				goto found;			}		}		/* not found-> insert new element in map (and hash) */		if (m) {			zz = mapsize;		} else {			entry.gid = *(oid*) BUNhead(b,p);		}		entry.hcur = hcur;		entry.l

⌨️ 快捷键说明

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