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

📄 bat5.mx

📁 一个内存数据库的源代码这是服务器端还有客户端
💻 MX
📖 第 1 页 / 共 5 页
字号:
comment "Alias for mmap(b,mode,mode,mode, mode,mode)";command setMemoryAdvise(b:bat[:any_1,:any_2], buns_mode:int, hheap_mode:int, 		theap_mode:int) :bit address BKCmadvisecomment "Modern Operating Systems allow users to influence the buffer         management policy of virtual memory. This is a crucial feature         for database systems, and eliminates the need to reimplement 	the OS in a database buffer manager.  The supported flags are         BUF_NORMAL (the normal adaptive kernel algorithm),	BUF_RANDOM (no page prefetching), 	BUF_SEQUENTIAL (prefetch and swapout),	BUF_WILLNEED (load everything with prefetch), 	BUF_DONTNEED (swapout).	These buffer management modes are not persistent. 	Returns the BAT operated upon.";command setMemoryAdvise(b:bat[:any_1,:any_2], mode:int):bit address BKCmadvise2comment "alias for madvise(b,mode,mode,mode, mode,mode)";command setHash(b:bat[:any_1,:any_2],prop:bit):bit address BKCsetHash;@- Synced BATsThe binary model of Monet has important advantages when working inmain-memory. Tables are thin and very efficiently processed. The binarymodel gives rise, however, to a larger-than-normal number of joinand semijoin operations. Relations are split up in vertical parts thatare very much related to each other. Then, for instance, multiplesimilar semijoins occur on different vertical parts. By equipping thekernel with knowledge about the correspondence of these parts, wecan greatly limit the amount of work to be done.When two BATs effectively contain the same sequence of head elements,we call them 'synced'. This is implemented by storing a very largeOID for each column. An update to the column destroys this OID.By comparing two OIDs the Monet kernel can very quickly decide thattwo columns are exactly equal. All BAT algebra operations propagatethese 'sync' OIDs with their own propagation rules.@malcommand isSynced (b1:bat[:any_1,:any_2], b2:bat[:any_3,:any_4]) :bit address BKCisSyncedcomment "Tests whether two BATs are synced or not. ";@- ConstantsThe following constants have not been integrated in the code base#Constants have been added to mal/const.mx prelude#    STORE_MEM   := 0;     # load into GDKmalloced memory#    STORE_MMAP  := 1;     # mmap() into virtual memory#    STORE_COMPR := 2;     # currently not implemented this way#    BUF_NORMAL    := 0;   # No further special treatment#    BUF_RANDOM    := 1;   # Expect random page references#    BUF_SEQUENTIAL:= 2;   # Expect sequential page references#    BUF_WILLNEED  := 3;   # Will need these pages#    BUF_DONTNEED  := 4;   # Don't need these pages@+ Implementation CodeIn Version 5, we are not going to support recursive BATs.It is up to the programmer to translate a bat into abat-name or batCacheid@-At this stage of the game, we should translatethe arguments of BATnew into types.Beware, a void column type is turned into a virtual oid type immediatelyby setting the sequential base.@+ Minimum and MaximumThe routines @`BATmin_@5(b) and @`BATmax_@5(b) compute the minimum andmaximum value of the tail column of a BAT.They are defined in the algebra.mx module.Aggregate values are calculated just before they are requested bythe user. They are not maintained continuously, because we expectthem to be used sparsely.@-@= atomaggr    if (s > 0 && !(BATtordered(b)&1)) {        char* nil = BATatoms[t].atomNull;        BUN p,q;        int xx;        BATloopFast(b, p, q, xx) {            x = (ptr) BUNt@2(b, p);            if (@3_CMP(x, nil, @4) == 0) {                v = nil; break;            }            if (@3_@5(x, v, @4)) {                v = x;            }        }    }    if (aggr) {       memcpy(aggr, x=v, ATOMsize(t));    } else {       /* alloc new space and copy the atom into it */       s = ATOMlen(t, v);       memcpy(x = (ptr) GDKmalloc(s), v, s);   }@= voidaggr    if (aggr) {        *(oid *) aggr = *(oid *) (x=v);    } else {        /* alloc new space and copy the atom into it */        memcpy(x = (ptr) GDKmalloc(sizeof(oid)), v, s);    }@= aggrmin    v = (s == 0)?ATOMnilptr(t):BUNtail(b, BUNfirst(b));    @:@5aggr(@1,@2,@3,@4,LT)@@= aggrmax    v = (s == 0)?ATOMnilptr(t):BUNtail(b, BUNlast(b)-BUNsize(b));    @:@5aggr(@1,@2,@3,@4,GT)@@h#ifndef _BAT_H_#define _BAT_H_#include <mal.h>#include <gdk.h>#ifdef WIN32#ifndef LIBBAT5#define bat5_export extern __declspec(dllimport)#else#define bat5_export extern __declspec(dllexport)#endif#else#define bat5_export extern#endifbat5_export char *BKCsetRole(int *r, int *bid, char **hname, char **tname);bat5_export char *BKCdestroyImmediate(signed char *r, int *bid);bat5_export char *BKCnewBATint(int *res, int *ht, int *tt, int *cap);bat5_export char *BKCgetAlpha(int *r, int *bid);bat5_export char *BKCgetDelta(int *r, int *bid);bat5_export char *BKCinsert_void_bun(int *r, int *bid, ptr t);bat5_export char *BKCinsert_bun(int *r, int *bid, ptr h, ptr t);bat5_export char *BKCinsert_bun_force(int *r, int *bid, ptr h, ptr t, bit *force);bat5_export char * BKCinsert_bun_oid_any(int *r, int *bid, ptr h, ptr t);bat5_export char * BKCinsert_bun_int_int(int *r, int *bid, int *h, int *t);bat5_export char * BKCinsert_bun_oid_str(int *r, int *bid, ptr h, ptr t);bat5_export char *BKCdelete(int *r, int *bid, ptr h);bat5_export char *BKCdelete_bat(int *r, int *bid, int *bnid);bat5_export char *BKCdelete_bun(int *r, int *bid, ptr h, ptr t);bat5_export char *BKCdestroy(signed char *r, int *bid);bat5_export char *BKCbat_append_void_bat_wrap(int *r, int *bid, int *uid);bat5_export char * BKCbat_append_val_wrap(int *r, int *bid, ptr u);bat5_export str BKCnewBATlng(int *res, int *ht, int *tt, lng *cap);bat5_export str BKCnewBat(int *res, int *ht, int *tt);bat5_export str BKCreverse(int *ret, int *bid);bat5_export str BKCmirror(int *ret, int *bid);bat5_export str BKCconvert(int *ret, int *bid);bat5_export str BKCrevert(int *ret, int *bid);bat5_export str BKCorder(int *ret, int *bid);bat5_export str BKCorder_rev(int *ret, int *bid);bat5_export str BKCinsert_bat(int *r, int *bid, int *sid);bat5_export str BKCinsert_bat_force(int *r, int *bid, int *sid, bit *force);bat5_export str BKCreplace_bun(int *r, int *bid, ptr h, ptr t);bat5_export str BKCreplace_bat(int *r, int *bid, int *sid);bat5_export str BKCreplace_bun_force(int *r, int *bid, ptr h, ptr t, bit *force);bat5_export str BKCreplace_bat_force(int *r, int *bid, int *sid, bit *force);bat5_export str BKCdelete_all(int *r, int *bid);bat5_export str BKCdelete_bat_bun(int *r, int *bid, int *sid);bat5_export str BKCdelete_bat(int *r, int *bid, int *sid);bat5_export str BKCdestroy_bat(bit *r, str *input);bat5_export str BKCappend_wrap(int *r, int *bid, int *uid);bat5_export str BKCappend_val_wrap(int *r, int *bid, ptr u);bat5_export str BKCappend_reverse_val_wrap(int *r, int *bid, ptr u);bat5_export str BKCappend_force_wrap(int *r, int *bid, int *uid, bit *force);bat5_export str BKCappend_val_force_wrap(int *r, int *bid, ptr u, bit *force);bat5_export str BKCbun_inplace(int *r, int *bid, oid *id, ptr t);bat5_export str BKCbat_inplace(int *r, int *bid, int *rid);bat5_export str BKCbun_inplace_force(int *r, int *bid, oid *id, ptr t, bit *force);bat5_export str BKCbat_inplace_force(int *r, int *bid, int *rid, bit *force);bat5_export str BKCgetCapacity(lng *res, int *bid);bat5_export str BKCgetHeadType(str *res, int *bid);bat5_export str BKCgetTailType(str *res, int *bid);bat5_export str BKCgetRole(str *res, int *bid);bat5_export str BKCsetkey(int *res, int *bid, bit *param);bat5_export str BKCsetSet(int *res, int *bid, bit *param);bat5_export str BKCisaSet(int *res, int *bid);bat5_export str BKCsetSorted(bit *res, int *bid);bat5_export str BKCisSorted(bit *res, int *bid);bat5_export str BKCisSortedReverse(bit *res, int *bid);bat5_export str BKCgetKey(bit *ret, int *bid);bat5_export str BKCpersists(int *r, int *bid, bit *flg);bat5_export str BKCsetPersistent(int *r, int *bid);bat5_export str BKCisPersistent(bit *res, int *bid);bat5_export str BKCsetTransient(int *r, int *bid);bat5_export str BKCisTransient(bit *res, int *bid);bat5_export str BKCaccess(int *res, int *bid, int *m);bat5_export str BKCsetAccess(int *res, int *bid, str *param);bat5_export str BKCgetAccess(str *res, int *bid);bat5_export str BKCinfo(int *retval, int *bid);bat5_export str BKCbatsize(lng *tot, int *bid);bat5_export str BKCbatsize_str(lng *tot, str batname);bat5_export str BKCisSynced(bit *ret, int *bid1, int *bid2);bat5_export str BKCsetColumn(int *r, int *bid, str *tname);bat5_export str BKCsetColumns(int *r, int *bid, str *hname, str *tname);bat5_export str BKCsetName(int *r, int *bid, str *s);bat5_export str BKCgetBBPname(str *ret, int *bid);bat5_export str BKCunload(bit *res, str *input);bat5_export str BKCisCached(int *res, int *bid);bat5_export str BKCload(int *res, str *input);bat5_export str BKChot(int *res, str *input);bat5_export str BKCcold(int *res, str *input);bat5_export str BKCcoldBAT(int *res, int *bid);bat5_export str BKCheat(int *res, str *input);bat5_export str BKChotBAT(int *res, int *bid);bat5_export str BKCsave(bit *res, str *input);bat5_export str BKCsave2(int *r, int *bid);bat5_export str BKCmmap(int *res, int *bid, int *bns, int *hhp, int *thp);bat5_export str BKCmmap2(int *res, int *bid, int *bns);bat5_export str BKCmadvise(int *res, int *bid, int *bns, int *hhp, int *thp);bat5_export str BKCmadvise2(int *res, int *bid, int *mode);bat5_export str BKCaccbuild(int *ret, int *bid, str *acc, ptr *param);bat5_export str BKCaccbuild_std(int *ret, int *bid, int *acc);bat5_export str BKCsetHash(bit *ret, int *bid, bit *prop);bat5_export str BKCsetSequenceBase(int *r, int *bid, oid *o);bat5_export str BKCsetSequenceBaseNil(int *r, int *bid, oid *o);bat5_export str BKCgetSequenceBase(oid *r, int *bid);bat5_export ssize_t void_replace_bat5(BAT *b, BAT *u, bit force);bat5_export int void_inplace5(BAT *b, oid id, ptr val, bit force);bat5_export int CMDbatsize(lng *tot, BAT *b);#endif /*_BAT_H_*/@c#include "mal_config.h"#include "bat5.h"#include <stream.h>#include "mal_exception.h"@-@= batconvert	(BAT@2type(@1) == TYPE_bat)?(BUN)&((BAT*)@2)->batCacheid:(BUN)@2@+ Information Functions@cintCMDnew_lng(BAT **ret, int *ht, int *tt, lng *cap){	if (*cap < 0)		*cap = 0;	*ret = BATnew(*ht, *tt, (size_t) * cap);	if (*ret)		(*ret)->batDirty |= 2;	return (*ret) ? GDK_SUCCEED : GDK_FAIL;}intCMDnew(BAT **ret, int *ht, int *tt, int *cap){	if (*cap < 0)		*cap = 0;	*ret = BATnew(*ht, *tt, (size_t) * cap);	if (*ret)		(*ret)->batDirty |= 2;	return (*ret) ? GDK_SUCCEED : GDK_FAIL;}intCMDnew_default(BAT **ret, int *ht, int *tt){	int default_size = 0;	return CMDnew(ret, ht, tt, &default_size);}intCMDreverse(BAT **ret, BAT *b){	*ret = BATmirror(b);	BBPfix(b->batCacheid);	return GDK_SUCCEED;}intCMDmirror(BAT **ret, BAT *b){	BAT *v = *ret = VIEWcombine(b);	if (b->batRestricted == BAT_WRITE) {		*ret = BATcopy(v, v->htype, v->ttype, FALSE);		BBPreclaim(v);	}	return (*ret) ? GDK_SUCCEED : GDK_FAIL;}intCMDconvert(BAT **ret, BAT *b){	if (BATconvert(*ret = b, CONV_HTON) == NULL)		BBPfix(b->batCacheid);	return GDK_SUCCEED;}intCMDrevert(BAT **ret, BAT *b){	if (BATrevert(*ret = b) == NULL)		return GDK_FAIL;	BBPfix(b->batCacheid);	return GDK_SUCCEED;}intCMDorder(BAT **ret, BAT *b){	if (BATorder(*ret = b) == NULL)		return GDK_FAIL;	BBPfix(b->batCacheid);	return GDK_SUCCEED;}intCMDorder_rev(BAT **ret, BAT *b){	if (BATorder_rev(*ret = b) == NULL)		return GDK_FAIL;	BBPfix(b->batCacheid);	return GDK_SUCCEED;}intCMDinsert_bun(BAT **r, BAT *b, ptr h, ptr t){	if (BUNins(*r = b, @:batconvert(b,h)@, @:batconvert(b,t)@,FALSE) == NULL)		return GDK_FAIL;	BBPfix(b->batCacheid);	return GDK_SUCCEED;}intCMDinsert_bat(BAT **r, BAT *b, BAT *s){	if (BATins(*r = b, s, FALSE) == NULL)		return GDK_FAIL;	BBPfix(b->batCacheid);	return GDK_SUCCEED;}intCMDreplace_bun(BAT **r, BAT *b, ptr h, ptr t){	if (BUNreplace(*r = b, @:batconvert(b,h)@, @:batconvert(b,t)@, 0) == NULL)		return GDK_FAIL;	BBPfix(b->batCacheid);	return GDK_SUCCEED;}intCMDreplace_bat(BAT **r, BAT *b, BAT *s){	if (BATreplace(*r = b, s, 0) == NULL)		return GDK_FAIL;	BBPfix(b->batCacheid);	return GDK_SUCCEED;}intCMDdelete_bun(BAT **r, BAT *b, ptr h, ptr t){	if (BUNdel(*r = b, h, t, FALSE) == NULL)		return GDK_FAIL;	BBPfix(b->batCacheid);	return GDK_SUCCEED;}intCMDdelete_head(BAT **r, BAT *b, ptr h){	if (BUNdelHead(*r = b, @:batconvert(b,h)@, FALSE) == NULL)		return GDK_FAIL;	BBPfix(b->batCacheid);	return GDK_SUCCEED;}intCMDdelete_all(BAT **r, BAT *b){	if (BATclear(*r = b) == NULL)		return GDK_FAIL;	BBPfix(b->batCacheid);	return GDK_SUCCEED;}intCMDdelete_bat_bun(BAT **r, BAT *b, BAT *s){	if (BATdel(*r = b, s, FALSE) == NULL)		return GDK_FAIL;	BBPfix(b->batCacheid);	return GDK_SUCCEED;}intCMDdelete_bat_head(BAT **r, BAT *b, BAT *s){	if (BATdelHead(*r = b, s, FALSE) == NULL)		return GDK_FAIL;	BBPfix(b->batCacheid);	return GDK_SUCCEED;}@-The next collection of operators fill a hole in the MonetDB kernel libraries.It provide handy operations on void-BATs.@cintvoid_inplace5(BAT *b, oid id, ptr val, bit force){	int res = GDK_SUCCEED;	BUN p = NULL;	BUN oldInserted = b->batInserted;	assert(b->htype == TYPE_void);	assert(b->hseqbase != oid_nil);	assert(BATcount(b) > (id -b->hseqbase));	b->batInserted = NULL;	BUNfndVOID(p, b, (ptr) &id);	assert(p >= b->batInserted);	/* we don't want delete/ins */	assert(force || !b->batRestricted);	if (!BUNinplace(b, p, (ptr) &id, val, force))		 res = GDK_FAIL;	b->batInserted = oldInserted;	return res;}intbun_inplace(BAT **res, BAT *b, oid *id, ptr val ){	int ret = void_inplace5(b,*id,val,FALSE);	*res = b;	BBPfix(b->batCacheid);	return ret;}intbun_inplace_force(BAT **res, BAT *b, oid *id, ptr val, bit *force ){	int ret = void_inplace5(b,*id,val,*force);	*res = b;	BBPfix(b->batCacheid);	return ret;}ssize_tvoid_replace_bat5(BAT *b, BAT *u, bit force){	size_t nr = 0;	BUN r, s;	BATloop(u, r, s) {		oid updid = *(oid *) BUNhead(u, r);		ptr val = BUNtail(u, r);		if (void_inplace5(b, updid, val, force) == GDK_FAIL)			return -1;		nr++;	}	return nr;}intbat_inplace(BAT **res, BAT *o, BAT *d){	*res = o;	if (void_replace_bat5(o, d, FALSE) < 0)		return GDK_FAIL;	BBPfix(o->batCacheid);	return GDK_SUCCEED;}intbat_inplace_force(BAT **res, BAT *o, BAT *d, bit *force){	*res = o;	if (void_replace_bat5(o, d, *force) < 0)		return GDK_FAIL;	BBPfix(o->batCacheid);	return GDK_SUCCEED;}/* descriptors may be unloaded by BBPtrim, so secure them with a hotfix while in use */static BAT *lock_desc(bat bid){	BBPfix(bid);	return (BAT *) BBPgetdesc(bid);}

⌨️ 快捷键说明

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