📄 gdk_atoms.mx
字号:
@' The contents of this file are subject to the MonetDB Public License@' Version 1.1 (the "License"); you may not use this file except in@' compliance with the License. You may obtain a copy of the License at@' http://monetdb.cwi.nl/Legal/MonetDBLicense-1.1.html@'@' Software distributed under the License is distributed on an "AS IS"@' basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the@' License for the specific language governing rights and limitations@' under the License.@'@' The Original Code is the MonetDB Database System.@'@' The Initial Developer of the Original Code is CWI.@' Portions created by CWI are Copyright (C) 1997-2007 CWI.@' All Rights Reserved.@f gdk_atoms@a M. L. Kersten, P. Boncz@* Atomic typesThe Binary Association Table library assumes efficient implementation ofthe atoms making up the binary association.This section describes the preliminaries for handlingboth built-in and user-defined atomic types. New types, such as point and polygons, can be readily added to thiscollection.@-@{@h#ifndef _GDK_ATOMS_H_#define _GDK_ATOMS_H_#include "gdk.h"#define MAXATOMS 128@- comparison macro'sIn order to get maximum performance, we extensively use out-factoringof typechecks using Mx macros. To catch diverging code in one Mx macrowe use the following #defines for comparing atoms:@h#define simple_CMP(x,y,tpe) (simple_LT(x,y,tpe)?-1:simple_GT(x,y,tpe))#define simple_EQ(x,y,tpe) ((*(tpe*) (x)) == (*(tpe*) (y)))#define simple_LT(x,y,tpe) ((*(tpe*) (x)) < (*(tpe*) (y)))#define simple_GT(x,y,tpe) ((*(tpe*) (x)) > (*(tpe*) (y)))#define simple_LE(x,y,tpe) ((*(tpe*) (x)) <= (*(tpe*) (y)))#define simple_GE(x,y,tpe) ((*(tpe*) (x)) >= (*(tpe*) (y)))#define atom_CMP(x,y,id) (*BATatoms[id].atomCmp)(x,y)#define atom_EQ(x,y,id) ((*BATatoms[id].atomCmp)(x,y) == 0)#define atom_LT(x,y,id) ((*BATatoms[id].atomCmp)(x,y) < 0)#define atom_GT(x,y,id) ((*BATatoms[id].atomCmp)(x,y) > 0)#define atom_LE(x,y,id) ((*BATatoms[id].atomCmp)(x,y) <= 0)#define atom_GE(x,y,id) ((*BATatoms[id].atomCmp)(x,y) >= 0)#define simple_HASH(v,tpe,dst) ((dst) *(tpe *) (v))#define atom_HASH(v,id,dst) ((dst) (*BATatoms[id].atomHash)(v))@- maximum atomic string lengths@h#define bitStrlen 8#define chrStrlen 8#define bteStrlen 8#define shtStrlen 12#define intStrlen 24#if SIZEOF_OID == SIZEOF_INT#define oidStrlen 24#else#define oidStrlen 48#endif#if SIZEOF_WRD == SIZEOF_INT#define wrdStrlen 24#else#define wrdStrlen 48#endif#if SIZEOF_PTR == SIZEOF_INT#define ptrStrlen 24#else#define ptrStrlen 48#endif#define lngStrlen 48#define fltStrlen 48#define dblStrlen 96@- The system comes with the traditional atomic types: int (4 bytes), bool(1 byte) and str (variable). In addition, we support the notion of an OID type, which ensures uniqueness of its members.This leads to the following type descriptor table.@h#ifdef __cplusplusextern "C" {#endifgdk_export int voidFromStr(str src, int *len, void **dst);gdk_export int voidToStr(str *dst, int *len, void *src);gdk_export void *voidRead(void *a, stream *s, size_t cnt);gdk_export int voidWrite(void *a, stream *s, size_t cnt);gdk_export int lngFromStr(str src, int *len, lng **dst);gdk_export int lngToStr(str *dst, int *len, lng *src);gdk_export lng *lngRead(lng *a, stream *s, size_t cnt);gdk_export int lngWrite(lng *a, stream *s, size_t cnt);int lngCmp(lng *r, lng *l);hash_t lngHash(lng *l);gdk_export int intFromStr(str src, int *len, int **dst);gdk_export int intToStr(str *dst, int *len, int *src);gdk_export int *intRead(int *a, stream *s, size_t cnt);gdk_export int intWrite(int *a, stream *s, size_t cnt);gdk_export int intCmp(int *r, int *l);hash_t intHash(int *i);gdk_export int batFromStr(str src, int *len, bat **dst);gdk_export int batToStr(str *dst, int *len, bat *src);gdk_export bat *batRead(bat *a, stream *s, size_t cnt);gdk_export int batWrite(bat *a, stream *s, size_t cnt);gdk_export int ptrFromStr(str src, int *len, ptr **dst);gdk_export int ptrToStr(str *dst, int *len, ptr *src);gdk_export ptr *ptrRead(ptr *a, stream *s, size_t cnt);gdk_export int ptrWrite(ptr *a, stream *s, size_t cnt);gdk_export int bitFromStr(str src, int *len, bit **dst);gdk_export int bitToStr(str *dst, int *len, bit *src);gdk_export bit *bitRead(bit *a, stream *s, size_t cnt);gdk_export int bitWrite(bit *a, stream *s, size_t cnt);gdk_export int OIDfromStr(str src, int *len, oid **dst);gdk_export int OIDtoStr(str *dst, int *len, oid *src);gdk_export oid *oidRead(oid *a, stream *s, size_t cnt);gdk_export int oidWrite(oid *a, stream *s, size_t cnt);gdk_export int shtFromStr(str src, int *len, sht **dst);gdk_export int shtToStr(str *dst, int *len, sht *src);gdk_export sht *shtRead(sht *a, stream *s, size_t cnt);gdk_export int shtWrite(sht *a, stream *s, size_t cnt);int shtCmp(sht *r, sht *l);hash_t shtHash(sht *s);gdk_export int bteFromStr(str src, int *len, bte **dst);gdk_export int bteToStr(str *dst, int *len, bte *src);gdk_export bte *bteRead(bte *a, stream *s, size_t cnt);gdk_export int bteWrite(bte *a, stream *s, size_t cnt);int bteCmp(bte *r, bte *l);hash_t bteHash(bte *c);gdk_export int chrFromStr(str src, int *len, chr **dst);gdk_export int chrToStr(str *dst, int *len, chr *src);gdk_export chr *chrRead(chr *a, stream *s, size_t cnt);gdk_export int chrWrite(chr *a, stream *s, size_t cnt);int chrCmp(chr *r, chr *l);hash_t chrHash(chr *c);gdk_export int fltFromStr(str src, int *len, flt **dst);gdk_export int fltToStr(str *dst, int *len, flt *src);gdk_export flt *fltRead(flt *a, stream *s, size_t cnt);gdk_export int fltWrite(flt *a, stream *s, size_t cnt);int fltCmp(flt *r, flt *l);gdk_export int dblFromStr(str src, int *len, dbl **dst);gdk_export int dblToStr(str *dst, int *len, dbl *src);gdk_export dbl *dblRead(dbl *a, stream *s, size_t cnt);gdk_export int dblWrite(dbl *a, stream *s, size_t cnt);int dblCmp(dbl *r, dbl *l);gdk_export ssize_t GDKstrFromStr(unsigned char *src, unsigned char *dst, ssize_t len);gdk_export int strFromStr(str src, int *len, str *dst);gdk_export int strToStr(str *dst, int *len, str src);gdk_export str strRead(str a, stream *s, size_t cnt);gdk_export int strWrite(str a, stream *s, size_t cnt);gdk_export hash_t strHash(str s);gdk_export void strCleanHash(Heap *hp, int rebuild);gdk_export var_t strPut(Heap *b, var_t *off, str src);gdk_export void strHeap(Heap *d, size_t cap);gdk_export int strLen(const char *s);gdk_export int strCmp(str l, str r);gdk_export int strNil(str s);gdk_export void strHeapConvert(Heap *h, int directon);gdk_export int strElimDoubles(Heap *h);gdk_export var_t strLocate(Heap *h, str v);gdk_export int strCmpNoNil(unsigned char *l, unsigned char *r);#ifdef __cplusplus}#endif@- inline comparison routinesReturn 0 on l==r, < 0 iff l < r, >0 iff l > r @c#include "monetdb_config.h"#include "gdk.h"#include <math.h> /* for INFINITY and NAN */intchrCmp(chr *l, chr *r){ return simple_CMP(l, r, chr);}intbteCmp(bte *l, bte *r){ return simple_CMP(l, r, bte);}intshtCmp(sht *l, sht *r){ return simple_CMP(l, r, sht);}intintCmp(int *l, int *r){ return simple_CMP(l, r, int);}intfltCmp(flt *l, flt *r){ return simple_CMP(l, r, flt);}intlngCmp(lng *l, lng *r){ return simple_CMP(l, r, lng);}intdblCmp(dbl *l, dbl *r){ return simple_CMP(l, r, dbl);}@- inline hash routinesReturn some positive integer derived from one atom value.@chash_tchrHash(chr *v){ return (hash_t) *(unsigned char *) v;}hash_tbteHash(bte *v){ return (hash_t) *(unsigned char *) v;}hash_tshtHash(sht *v){ return (hash_t) mix_sht(*(unsigned short *) v);}hash_tintHash(int *v){ return (hash_t) mix_int(*(unsigned int *) v);}hash_tlngHash(lng *v){ return (hash_t) mix_int(((unsigned int *) v)[0] ^ ((unsigned int *) v)[1]);}@+ Standard Atoms@cstatic INLINE voidshtConvert(sht *s){ *s = short_int_SWAP(*s);}static INLINE voidintConvert(int *s){ *s = normal_int_SWAP(*s);}static INLINE voidlngConvert(lng *s){ *s = long_long_SWAP(*s);}static INLINE intbatFix(bat *b){ return BBPincref(*b, TRUE);}static INLINE intbatUnfix(bat *b){ return BBPdecref(*b, TRUE);}atomDesc BATatoms[MAXATOMS] = { {"void",#if SIZEOF_OID == SIZEOF_INT TYPE_void, 1, 0, /* sizeof(@`void@7) */ 0, 0, 1, (ptr) &int_nil, (int (*)(str, int *, ptr *)) OIDfromStr, (int (*)(str *, int *, ptr)) OIDtoStr, (void *(*)(void *, stream *, size_t)) voidRead, (int (*)(void *, stream *, size_t)) voidWrite, (int (*)(ptr, ptr)) intCmp, (hash_t (*)(ptr)) intHash, 0,#else TYPE_void, 1, 0, /* sizeof(@`void@7) */ 0, 0, 1, (ptr) &lng_nil, (int (*)(str, int *, ptr *)) OIDfromStr, (int (*)(str *, int *, ptr)) OIDtoStr, (void *(*)(void *, stream *, size_t)) voidRead, (int (*)(void *, stream *, size_t)) voidWrite, (int (*)(ptr, ptr)) lngCmp, (hash_t (*)(ptr)) lngHash, 0,#endif 0, 0, 0, 0, 0, 0, 0, 0}, {"bit", TYPE_chr, 1, sizeof(bit), sizeof(@`bit@7), 0, 0, (ptr) &chr_nil, (int (*)(str, int *, ptr *)) bitFromStr, (int (*)(str *, int *, ptr)) bitToStr, (void *(*)(void *, stream *, size_t)) bitRead, (int (*)(void *, stream *, size_t)) bitWrite, (int (*)(ptr, ptr)) chrCmp, (hash_t (*)(ptr)) chrHash, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {"chr", TYPE_chr, 1, sizeof(chr), sizeof(@`chr@7), 0, 0, (ptr) &chr_nil, (int (*)(str, int *, ptr *)) @`chrFromStr@5, (int (*)(str *, int *, ptr)) @`chrToStr@5, (void *(*)(void *, stream *, size_t)) chrRead, (int (*)(void *, stream *, size_t)) chrWrite, (int (*)(ptr, ptr)) chrCmp, (hash_t (*)(ptr)) chrHash, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {"bte", TYPE_bte, 1, sizeof(bte), sizeof(@`bte@7), 0, 0, (ptr) &bte_nil, (int (*)(str, int *, ptr *)) @`bteFromStr@5, (int (*)(str *, int *, ptr)) @`bteToStr@5, (void *(*)(void *, stream *, size_t)) bteRead, (int (*)(void *, stream *, size_t)) bteWrite, (int (*)(ptr, ptr)) bteCmp, (hash_t (*)(ptr)) bteHash, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {"sht", TYPE_sht, 1, sizeof(sht), sizeof(@`sht@7), 0, 0, (ptr) &sht_nil, (int (*)(str, int *, ptr *)) @`shtFromStr@5, (int (*)(str *, int *, ptr)) @`shtToStr@5, (void *(*)(void *, stream *, size_t)) shtRead, (int (*)(void *, stream *, size_t)) shtWrite, (int (*)(ptr, ptr)) shtCmp, (hash_t (*)(ptr)) shtHash, (void (*)(ptr, int)) shtConvert, 0, 0, 0, 0, 0, 0, 0, 0}, {"BAT", TYPE_int, 1, sizeof(bat), sizeof(@`bat@7), 0, 0, (ptr) &int_nil, (int (*)(str, int *, ptr *)) batFromStr, (int (*)(str *, int *, ptr)) batToStr, (void *(*)(void *, stream *, size_t)) batRead, (int (*)(void *, stream *, size_t)) batWrite, (int (*)(ptr, ptr)) intCmp, (hash_t (*)(ptr)) intHash, (void (*)(ptr, int)) intConvert, (int (*)(ptr)) batFix, (int (*)(ptr)) batUnfix, 0, 0, 0, 0, 0, 0}, {"int", TYPE_int, 1, sizeof(int), sizeof(@`int@7), 0, 0, (ptr) &int_nil, (int (*)(str, int *, ptr *)) intFromStr, (int (*)(str *, int *, ptr)) @`intToStr@5, (void *(*)(void *, stream *, size_t)) intRead, (int (*)(void *, stream *, size_t)) intWrite, (int (*)(ptr, ptr)) intCmp, (hash_t (*)(ptr)) intHash, (void (*)(ptr, int)) intConvert, 0, 0, 0, 0, 0, 0, 0, 0}, {"oid",#if SIZEOF_OID == SIZEOF_INT TYPE_int, 1, sizeof(oid), sizeof(@`oid@7), 0, 0, (ptr) &int_nil, (int (*)(str, int *, ptr *)) OIDfromStr, (int (*)(str *, int *, ptr)) OIDtoStr, (void *(*)(void *, stream *, size_t)) intRead, (int (*)(void *, stream *, size_t)) intWrite, (int (*)(ptr, ptr)) intCmp, (hash_t (*)(ptr)) intHash, (void (*)(ptr, int)) intConvert,#else TYPE_lng, 1, sizeof(oid), sizeof(@`oid@7), 0, 0, (ptr) &lng_nil, (int (*)(str, int *, ptr *)) OIDfromStr, (int (*)(str *, int *, ptr)) OIDtoStr, (void *(*)(void *, stream *, size_t)) lngRead, (int (*)(void *, stream *, size_t)) lngWrite, (int (*)(ptr, ptr)) lngCmp, (hash_t (*)(ptr)) lngHash, (void (*)(ptr, int)) lngConvert,#endif 0, 0, 0, 0, 0, 0, 0, 0}, {"wrd",#if SIZEOF_WRD == SIZEOF_INT TYPE_int, 1, sizeof(wrd), sizeof(@`wrd@7), 0, 0, (ptr) &int_nil, (int (*)(str, int *, ptr *)) intFromStr, (int (*)(str *, int *, ptr)) intToStr, (void *(*)(void *, stream *, size_t)) intRead, (int (*)(void *, stream *, size_t)) intWrite, (int (*)(ptr, ptr)) intCmp, (hash_t (*)(ptr)) intHash, (void (*)(ptr, int)) intConvert,#else TYPE_lng, 1, sizeof(wrd), sizeof(@`wrd@7), 0, 0, (ptr) &lng_nil, (int (*)(str, int *, ptr *)) lngFromStr, (int (*)(str *, int *, ptr)) lngToStr, (void *(*)(void *, stream *, size_t)) lngRead, (int (*)(void *, stream *, size_t)) lngWrite, (int (*)(ptr, ptr)) lngCmp, (hash_t (*)(ptr)) lngHash, (void (*)(ptr, int)) lngConvert,#endif 0, 0, 0, 0, 0, 0, 0, 0}, {"ptr",#if SIZEOF_VOID_P == SIZEOF_INT TYPE_int, 1, sizeof(ptr), sizeof(@`ptr@7), 0, 0, (ptr) &int_nil, (int (*)(str, int *, ptr *)) @`ptrFromStr@5, (int (*)(str *, int *, ptr)) @`ptrToStr@5, (void *(*)(void *, stream *, size_t)) ptrRead, (int (*)(void *, stream *, size_t)) ptrWrite, (int (*)(ptr, ptr)) intCmp, (hash_t (*)(ptr)) intHash, (void (*)(ptr, int)) intConvert,#else /* SIZEOF_VOID_P == SIZEOF_LNG */ TYPE_lng, 1, sizeof(ptr), sizeof(@`ptr@7), 0, 0, (ptr) &lng_nil, (int (*)(str, int *, ptr *)) @`ptrFromStr@5, (int (*)(str *, int *, ptr)) @`ptrToStr@5, (void *(*)(void *, stream *, size_t)) ptrRead, (int (*)(void *, stream *, size_t)) ptrWrite, (int (*)(ptr, ptr)) lngCmp, (hash_t (*)(ptr)) lngHash, (void (*)(ptr, int)) lngConvert,#endif 0, 0, 0, 0, 0, 0, 0, 0}, {"flt", TYPE_flt, 1, sizeof(flt), sizeof(@`flt@7), 0, 0, (ptr) &flt_nil, (int (*)(str, int *, ptr *)) @`fltFromStr@5, (int (*)(str *, int *, ptr)) @`fltToStr@5, (void *(*)(void *, stream *, size_t)) fltRead, (int (*)(void *, stream *, size_t)) fltWrite, (int (*)(ptr, ptr)) fltCmp, (hash_t (*)(ptr)) intHash, (void (*)(ptr, int)) intConvert, 0, 0, 0, 0, 0, 0, 0, 0}, {"dbl", TYPE_dbl, 1, sizeof(dbl), sizeof(@`dbl@7), 0, 0, (ptr) &dbl_nil, (int (*)(str, int *, ptr *)) @`dblFromStr@5, (int (*)(str *, int *, ptr)) @`dblToStr@5, (void *(*)(void *, stream *, size_t)) dblRead, (int (*)(void *, stream *, size_t)) dblWrite, (int (*)(ptr, ptr)) dblCmp, (hash_t (*)(ptr)) lngHash, (void (*)(ptr, int)) lngConvert, 0, 0, 0, 0, 0, 0, 0, 0}, {"lng", TYPE_lng, 1, sizeof(lng), sizeof(@`lng@7), 0, 0, (ptr) &lng_nil, (int (*)(str, int *, ptr *)) lngFromStr, (int (*)(str *, int *, ptr)) lngToStr, (void *(*)(void *, stream *, size_t)) lngRead, (int (*)(void *, stream *, size_t)) lngWrite, (int (*)(ptr, ptr)) lngCmp, (hash_t (*)(ptr)) lngHash, (void (*)(ptr, int)) lngConvert, 0, 0, 0, 0, 0, 0, 0, 0}, {"str", TYPE_str, 1, sizeof(var_t), sizeof(var_t), 0, 1, (ptr) str_nil, (int (*)(str, int *, ptr *)) strFromStr, (int (*)(str *, int *, ptr)) strToStr, (void *(*)(void *, stream *, size_t)) strRead, (int (*)(void *, stream *, size_t)) strWrite, (int (*)(ptr, ptr)) strCmp, (hash_t (*)(ptr)) strHash, 0, 0, 0, (var_t (*)(Heap *, var_t *, ptr)) strPut, 0, (int (*)(ptr)) strLen, strHeap, (void (*)(Heap *, int)) strHeapConvert, 0},};int GDKatomcnt = TYPE_str + 1;@@}@+ Atomic Type InterfaceThe collection of built-in types supported for BATs can be extended easily.In essence, the user should specify conversion routines from values storedanywhere in memory to its equivalent in the BAT, and vice verse.Some routines are required for coercion and to support the BATadministration.A new type is incrementally build using the routine @%ATOMproperty(id, property, value)@.The parameter @%id@ denotes the type name; an entry is created if the typeis so far unknown. The @%property@ argument is a string identifying thetype description property to be updated. Valid propertynames are @%size, tostr, fromstr, put, get, cmp, eq, del, hash, null@,@%new@, and @%heap@.The size describes the amount of space to be reserved in the BUN.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -