gdk.mx

来自「这个是内存数据库中的一个管理工具」· MX 代码 · 共 1,875 行 · 第 1/5 页

MX
1,875
字号
	int len, vtype;} *ValPtr, ValRecord;#define VALptr(v) (ATOMextern((v)->vtype)?(v)->val.pval:(ptr)&(v)->val.ival)#define VALnil(v,t) VALset(v,t,ATOMextern(t)?ATOMnil(t):ATOMnilptr(t))/* interface definitions */gdk_export ValPtr VALnew(void);gdk_export ptr VALconvert(int typ, ValPtr t);gdk_export ptr VALconvert1(int typ, ValPtr src, ValPtr dst);gdk_export ptr VALconvert2(int typ, ValPtr src, ValPtr dst);gdk_export int VALformat(char **buf, ValPtr res);gdk_export int VALprint(stream *fd, ValPtr res);gdk_export ValPtr VALcopy(ValPtr dst, ValPtr src);gdk_export ValPtr VALinit(ValPtr d, int tpe, ptr s);gdk_export void VALempty(ValPtr v);gdk_export void VALclear(ValPtr v);gdk_export ValPtr VALset(ValPtr v, int t, ptr p);gdk_export void *VALget(ValPtr v);@}@- The BAT recordThe elements of the BAT structure are introduced in the remainder.Instead of using the underlying types hidden beneath it, one shoulduse a @%BAT@ type that is supposed to look like this:@verbatimtypedef struct {          /* static BAT properties */          bat    batCacheid;       /* bat id: index in BBPcache */          int    batPersistence;   /* persistence mode */          bit    batCopiedtodisk;  /* BAT is saved on disk? */          bit    batSet;           /* all tuples in the BAT are unique? */          sht    batElmshift       /* log2 of width  */          sht    batElmsize        /* width in byte of the BUNs */          /* dynamic BAT properties */          int    batHeat;          /* heat of BAT in the BBP */          sht    batDirty;         /* BAT modified after last commit? */          bit    batDirtydesc;     /* BAT descriptor specific dirty flag */          bit    batDirtybuns;     /* BUN heap specific dirty flag */          Heap*  batBuns;          /* Heap where the buns are stored */          /* DELTA status */          BUN    batDeleted;       /* first deleted BUN */          BUN    batFirst;         /* empty BUN before the first alive BUN */          BUN    batInserted;      /* first inserted BUN */          size_t batCount;         /* Tuple count */          /* Head properties */          int    htype;            /* Head type number */          str    hident;           /* name for head column */          bit    hkey;             /* head values should be unique? */          bit    hsorted;          /* are head values currently ordered? */          bit    hvarsized;        /* for speed: head type is varsized? */	  oid	 halign;	   /* alignment OID for head. */          bit    hheapdirty;       /* head heap specific dirty flag */          /* Head storage */          int    hloc;             /* byte-offset in BUN for head elements */          Heap   *hheap;           /* heap for varsized head values */          Hash   *hhash;           /* linear chained hash table on head */          /* Tail properties */          int    ttype;            /* Tail type number */          str    tident;           /* name for tail column */          bit    tkey;             /* tail values should be unique? */          bit    tsorted;          /* are tail values currently ordered? */          bit    tvarsized;        /* for speed: tail type is varsized? */	  oid	 talign;	   /* alignment OID for head. */          bit    theapdirty;       /* tail heap specific dirty flag */          /* Tail storage */          int    tloc;             /* byte-offset in BUN for tail elements */          Heap   theap;            /* heap for varsized tail values */          Hash   thash;            /* linear chained hash table on tail */ } BAT;@end verbatimThe internal structure of the @strong{BAT} record is in fact much more complex,but GDK programmers should refrain of making use of that.The reason for this complex structure isto allow for a BAT to exist in two incarnations at the time: the@emph{normal view} and the @emph{reversed view}. Each bat @emph{b} has a BATmirror(@emph{b}) which has the negative @strong{cacheid} of b in the BBP.Since we don't want to pay cost to keep both views in line with each otherunder BAT updates, we work with shared pieces of memory betweenthe two views. An update to one will thus automatically update the other.In the same line, we allow @strong{synchronized BATs} (BATs with identicalhead columns, and marked as such in the @strong{BAT Alignment} interface) now tobe clustered horizontally. @c image{http://monetdb.cwi.nl/projects/monetdb-mk/imgs/bat2,,,,feps}@@{@htypedef struct {	chr headtype;		/* type id. */	chr tailtype;		/* type id. */	unsigned short headloc;	/* offset into bun. */	unsigned short tailloc;	/* offset into bun. */	bit headkey;		/* duplicates allowed? */	bit tailkey;		/* duplicates allowed? */	bit headvarsized;	/* varsized(>0) or fixedsized(0). */	bit tailvarsized;	/* varsized(>0) or fixedsized(0). */	chr bunshift;		/* log2 of bunwidth */	unsigned short bunwidth; /* byte-width of BUN array */	oid hseq;		/* start of dense head sequence */	oid tseq;		/* start of dense tail sequence */} Dimensions;typedef struct {	MT_Id tid;		/* which thread created it */	int stamp;		/* BAT recent creation stamp */	unsigned int	    copiedtodisk:1,	/* once written */	    dirty:2,		/* dirty wrt disk? */	    dirtyflushed:1,	/* was dirty before commt started? */	    descdirty:1,	/* bat descriptor dirty marker */	    bunsdirty:1,	/* bun heap dirty marker */	    lview:1,		/* bat is a *logical* view on parentid */	    unused:25;		/* value=0 for now */	chr set;		/* real set semantics */	chr restricted;		/* access priviliges */	sht persistence;	/* should the BAT persist on disk? */	int sharecnt;		/* incoming view count */	bat parentid;		/* cache id of VIEW parent bat */	bit map_dirty;		/* new mmap mode present */	char map_buns;		/* mmap mode for bun heap */	char map_hheap;		/* mmap mode for head atom heap */	char map_theap;		/* mmap mode for tail atom heap */} BATrec;typedef struct {	/* bunheap data */	Heap buns;		/* space for the buns. */	/* delta status administration */	BUN deleted;		/* start of deleted elements */	BUN first;		/* to store next deletion */	BUN inserted;		/* start of inserted elements */	size_t count;		/* tuple count */} BUNrec;typedef struct PROPrec {	int 	  id;	ValRecord v;	struct PROPrec *next;	/* simple chain of properties */} PROPrec;typedef struct {	str   id;		/* label for head/tail column */	Heap *vheap;		/* space for the head/tail column. */	chr heapdirty;		/* specific heap dirty marker */	bit sorted;		/* 0=false, 1=true; */	bit dense;		/* 0=false, 1=true; */	oid align;		/* OID for sync alignment */	size_t nosorted_rev;	/* position that proves sorted_rev==FALSE */	size_t nokey[2];	/* positions that prove key ==FALSE */	size_t nosorted;	/* position that proves sorted==FALSE */	size_t nodense;		/* position that proves dense==FALSE */	PROPrec *props;		/* list of dynamic properties stored in the bat descriptor */} COLrec;#define GDKLIBRARY_OLD  050415  /* 64-bits BAT with old hash function */#define GDKLIBRARY      061021  /* 64-bits BAT */typedef struct BAT {	/* static bat properties */	sht GDKversion;		/* FIRST! */	bat batCacheid;		/* index into BBP */	Dimensions dims;	/* BAT dimensions */	Heap *batBuns;		/* pointer to U->buns */	/* static column properties */	Hash *hhash;		/* head hash table */	Hash *thash;		/* tail hash table */	/* dynamic column properties */	COLrec *H;		/* column info */	COLrec *T;		/* column info */	/* dynamic bat properties */	BATrec *P;		/* cache and sort info */	BUNrec *U;		/* cache and sort info */	/* void hack fields */	int void_tid;		/* thread that reads this bat */	int void_cnt;		/* nr of reads */	oid void_seq1;	oid void_seq2;} BAT;@-The different parts of which a BAT consists are physically storednext to each other in the @%BATstore@ type.@htypedef struct {	BAT B;			/* storage for BAT descriptor */	COLrec H;		/* storage for head column */	COLrec T;		/* storage for tail column */	BATrec P;		/* storage for BATrec */	BUNrec U;		/* storage for BUNrec */} BATstore;typedef int (*GDKfcn) ();/* macros's to hide complexity of BAT structure */#define batPersistence	P->persistence#define batCopiedtodisk	P->copiedtodisk#define batSet		P->set#define batDirtyflushed	P->dirtyflushed#define batDirty	P->dirty#define batConvert	P->convert#define batDirtyflushed P->dirtyflushed#define batDirtydesc	P->descdirty#define batDirtybuns	P->bunsdirty#define hheapdirty	H->heapdirty#define theapdirty	T->heapdirty#define batFirst	U->first#define batInserted	U->inserted#define batDeleted	U->deleted#define batCount	U->count#define batParentid	P->parentid#define batLview	P->lview#define batStamp	P->stamp#define batSharecnt	P->sharecnt#define batRestricted	P->restricted#define batLastused	P->lastused#define creator_tid	P->tid#define batElmsize	dims.bunwidth#define batElmshift	dims.bunshift#define htype		dims.headtype#define ttype		dims.tailtype#define hloc		dims.headloc#define tloc		dims.tailloc#define hkey		dims.headkey#define tkey		dims.tailkey#define hvarsized	dims.headvarsized#define tvarsized	dims.tailvarsized#define hseqbase	dims.hseq#define tseqbase	dims.tseq#define hsorted		H->sorted#define tsorted		T->sorted#define hdense		H->dense#define tdense		T->dense#define hheap		H->vheap#define theap		T->vheap#define hident		H->id#define tident		T->id#define halign		H->align#define talign		T->align#define batMapdirty	P->map_dirty#define batMapbuns	P->map_buns#define batMaphheap	P->map_hheap#define batMaptheap	P->map_theap@@}@- Heap ManagementHeaps are the low-level entities of mass storage in BATs. Currently,they can either be stored on disk, loaded into memory, or memory mapped.@multitable @columnfractions 0.08 0.7@item int@tab HEAPalloc (Heap *h, size_t nitems, size_t itemsize);@item int@tab HEAPfree (Heap *h);@item int@tab HEAPextend (Heap *h, size_t size);@item int@tab HEAPload (Heap *h, str nme,ext, int trunc);@item int@tab HEAPsave (Heap *h, str nme,ext);@item int@tab HEAPcopy (Heap *dst,*src);@item int@tab HEAPdelete (Heap *dst, str o, str ext);@item int@tab HEAPwarm (Heap *h);@item int@end multitable@These routines should be used to alloc free or extend heaps;they isolate you from the different ways heaps can be accessed.@{@hgdk_export int HEAPalloc(Heap *h, size_t nitems, size_t itemsize);gdk_export int HEAPfree(Heap *h);gdk_export int HEAPextend(Heap *h, size_t size);gdk_export int HEAPload(Heap *h, str nme, str ext, int trunc);gdk_export int HEAPsave(Heap *h, str nme, str ext);gdk_export int HEAPcopy(Heap *dst, Heap *src);gdk_export int HEAPwarm(Heap *h);gdk_export size_t HEAPsubcopy(Heap *dst, Heap *src, size_t size, size_t offset);gdk_export int HEAPdelete(Heap *h, str o, str ext);gdk_export size_t HEAPvmsize(Heap *h);gdk_export size_t HEAPmemsize(Heap *h);@}@- Internal HEAP Chunk ManagementHeaps are used in BATs to store data for variable-size atoms.The implementor must manage malloc()/free() functionality foratoms in this heap. A standard implementation is provided here.@table @code@item voidHEAP_initialize  (Heap* h, size\_t nbytes, size\_t nprivate, int align )@item voidHEAP_destroy     (Heap* h)@item intHEAP_malloc      (Heap* heap, size\_t nbytes)@item voidHEAP_free        (Heap *heap, size\_t block)@item intHEAP_private     (Heap* h)@item voidHEAP_printstatus (Heap* h)@item voidHEAP_check       (Heap* h)@end tableThe heap space starts with a private space that is left untouched bythe normal chunk allocation.  You can use this private space e.g. tostore the root of an rtree@%HEAP_malloc@ allocates a chunk of memory on the heap, and returns anindex to it.  @%HEAP_free@ frees a previously allocated chunk@%HEAP_private@ returns an integer index to private space.@{@h/* structure used by HEAP_check functions */typedef struct {	size_t minpos;		/* minimum block byte-index */	size_t maxpos;		/* maximum block byte-index */	int alignment;		/* block index alignment */	size_t *validmask;	/* bitmap with all valid byte-indices				 * first bit corresponds with 'minpos';				 * 2nd bit with 'minpos+alignment', etc				 */} HeapRepair;gdk_export void HEAP_initialize(Heap *heap, /* nbytes -- Initial size of the heap. */				size_t nbytes, /* alignment -- for objects on the heap. */				size_t nprivate, /* nprivate -- Size of private space */				int alignment /* alignment restriction for allocated chunks */	);gdk_export void HEAP_initialize_compact(Heap *heap, /* nbytes -- Initial size of the heap. */					size_t nbytes, /* alignment -- for objects on the heap. */					size_t nprivate, /* nprivate -- Size of private space */					int alignment, /* alignment restriction for allocated chunks */					int (*sizefcn) (ptr) /* BATatoms[].atomLen function */	);gdk_export var_t HEAP_malloc(Heap *heap, size_t nbytes);gdk_export void HEAP_free(Heap *heap, var_t block);gdk_export size_t HEAP_private(Heap *h);gdk_export void HEAP_checkformat(Heap *h);gdk_export int HEAP_check(Heap *h, HeapRepair *hr);gdk_export void HEAP_init(Heap *heap, int tpe);gdk_export int HEAP_mmappable(Heap *heap);#define HEAP_index(HEAP,INDEX,TYPE)	((TYPE *)((char *) (HEAP)->base + (INDEX)))@}@- BAT construction@multitable @columnfractions 0.08 0.7@item @code{BAT* }@tab BATnew (int headtype, int tailtype, size_t cap)@item @code{BAT* }@tab BATclone (BAT *c, size_t cap)

⌨️ 快捷键说明

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