📄 mkey.c
字号:
#line 188 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/mkey.mx"#include "mal_config.h"#include "mkey.h"/* TODO: nil handling. however; we do not want to lose time in bulk_rotate_xor_hash with that */intCMDrotate(int *res, int *val, int *n){ *res = GDK_ROTATE(*val, *n, 32 - *n, (1 << *n) - 1); return GDK_SUCCEED;}intCMDhash_chr(int *res, chr *val){ *res = *(chr *) val; return GDK_SUCCEED;}intCMDhash_sht(int *res, sht *val){ *res = *(sht *) val; return GDK_SUCCEED;}intCMDhash_int(int *res, int *val){ *res = *(int *) val; return GDK_SUCCEED;}intCMDhash_flt(int *res, flt *val){ *res = *(int *) val; return GDK_SUCCEED;}intCMDhash_lng(int *res, lng *val){ *res = ((int *) val)[0] ^ ((int *) val)[1]; return GDK_SUCCEED;}intCMDhash_dbl(int *res, dbl *val){ *res = ((int *) val)[0] ^ ((int *) val)[1]; return GDK_SUCCEED;}intCMDhash_str(int *res, str val){ *res = strHash(val); return GDK_SUCCEED;}intCMDhash(int *res, ptr val, int tpe){ hash_t code; /* 64-bits on 64 systems; we truncate it here to save space */ switch (ATOMstorage(tpe)) { case TYPE_void: code = int_nil; break; case TYPE_chr: code = *(chr *) val; break; case TYPE_sht: code = *(sht *) val; break; case TYPE_int: case TYPE_flt: code = *(int *) val; break; case TYPE_lng: case TYPE_dbl: code = ((int *) val)[0] ^ ((int *) val)[1]; break; case TYPE_str: code = strHash((char*)val); break; default: code = (*BATatoms[tpe].atomHash) (val); } *res = code; return GDK_SUCCEED;}strMKEYrotate_xor_hash(MalBlkPtr mb, MalStkPtr stk, InstrPtr p){ int *dst = (int*) getArgReference(stk,p,0); int *h = (int*) getArgReference(stk,p,1); int *rotate = (int*) getArgReference(stk,p,2); int tpe = getArgType(mb,p,3); ptr *pval = (ptr) getArgReference(stk,p,3); int lbit = *rotate; int rbit = 32 - *rotate; int mask = (1 << lbit) - 1; if (tpe == TYPE_chr) { chr *cur = (chr*) pval; *dst = GDK_ROTATE(*h, lbit, rbit, mask) ^ *cur; } else if (tpe == TYPE_sht) { sht *cur = (sht*) pval; *dst = GDK_ROTATE(*h, lbit, rbit, mask) ^ *cur; } else if (tpe == TYPE_int || tpe == TYPE_flt) { int *cur = (int*) pval; *dst = GDK_ROTATE(*h, lbit, rbit, mask) ^ *cur; } else if (tpe == TYPE_lng || tpe == TYPE_dbl) { lng *cur = (lng*) pval; int val = (int)( cur[0] ^ cur[1]); *dst = GDK_ROTATE(*h, lbit, rbit, mask) ^ val; } else if (tpe == TYPE_str) { /* TYPE_str */ str cur = *(str*) pval; hash_t val = strHash(cur); *dst = GDK_ROTATE(*h, lbit, rbit, mask) ^ val; } else { hash_t (*hash) (ptr) = BATatoms[tpe].atomHash; *dst = GDK_ROTATE(*h, lbit, rbit, mask) ^ (*hash) (pval); } return MAL_SUCCEED;}intCMDbulk_rotate_xor_hash(BAT **res, BAT *bn, int *rotate, BAT *b){ int *dst = (int *) BUNtloc(bn, BUNfirst(bn)); int tpe = ATOMstorage(b->ttype); int lbit = *rotate; int rbit = 32 - *rotate; int mask = (1 << lbit) - 1; int xx = BUNsize(b); int yy = BUNsize(bn); if (!ALIGNsynced(bn, b)) { GDKerror("CMDbulk_rotate_xor_hash: (%s,%d,%s): not synced on head.\n", BATgetId(bn), *rotate, BATgetId(b)); return GDK_FAIL; } else if (VIEWparent(bn) || bn->batRestricted) { GDKerror("CMDbulk_rotate_xor_hash: (%s,%d,%s): left operand not writeable.\n", BATgetId(bn), *rotate, BATgetId(b)); return GDK_FAIL; } else if (*rotate < 0 || *rotate >= 32) { GDKerror("CMDbulk_rotate_xor_hash: (%s,%d,%s): illegal number of rotate bits.\n", BATgetId(bn), *rotate, BATgetId(b)); return GDK_FAIL; } else if (tpe == TYPE_chr) { chr *cur = (chr *) BUNtloc(b, BUNfirst(b)); chr *end = (chr *) BUNtloc(b, BUNlast(b)); while (cur < end) { *dst = GDK_ROTATE(*dst, lbit, rbit, mask) ^ *cur; cur = (chr *) (((BUN) cur) + xx); dst = (int *) (((BUN) dst) + yy); } } else if (tpe == TYPE_sht) { sht *cur = (sht *) BUNtloc(b, BUNfirst(b)); sht *end = (sht *) BUNtloc(b, BUNlast(b)); while (cur < end) { *dst = GDK_ROTATE(*dst, lbit, rbit, mask) ^ *cur; cur = (sht *) (((BUN) cur) + xx); dst = (int *) (((BUN) dst) + yy); } } else if (tpe == TYPE_int || tpe == TYPE_flt) { int *cur = (int *) BUNtloc(b, BUNfirst(b)); int *end = (int *) BUNtloc(b, BUNlast(b)); while (cur < end) { *dst = GDK_ROTATE(*dst, lbit, rbit, mask) ^ *cur; cur = (int *) (((BUN) cur) + xx); dst = (int *) (((BUN) dst) + yy); } } else if (tpe == TYPE_lng || tpe == TYPE_dbl) { int *cur = (int *) BUNtloc(b, BUNfirst(b)); int *end = (int *) BUNtloc(b, BUNlast(b)); while (cur < end) { int val = cur[0] ^ cur[1]; *dst = GDK_ROTATE(*dst, lbit, rbit, mask) ^ val; cur = (int *) (((BUN) cur) + xx); dst = (int *) (((BUN) dst) + yy); } } else if (tpe == TYPE_str) { /* TYPE_str */ int *cur = (int *) BUNtloc(b, BUNfirst(b)); int *end = (int *) BUNtloc(b, BUNlast(b)); str base = b->theap->base; while (cur < end) { hash_t val; val = strHash(base + *cur); *dst = GDK_ROTATE(*dst, lbit, rbit, mask) ^ val; cur = (int *) (((BUN) cur) + xx); dst = (int *) (((BUN) dst) + yy); } } else if (b->ttype == TYPE_void) { BUN p, q; BATloopFast(b, p, q, xx) { *dst = GDK_ROTATE(*dst, lbit, rbit, mask) ^ *(int *) BUNtail(b, p); dst = (int *) (((BUN) dst) + yy); } } else { hash_t (*hash) (ptr) = BATatoms[b->ttype].atomHash; BUN p, q; BATloopFast(b, p, q, xx) { *dst = GDK_ROTATE(*dst, lbit, rbit, mask) ^ (*hash) (BUNtail(b, p)); dst = (int *) (((BUN) dst) + yy); } } /* we return an already existing parameter BAT, so we must fix it */ *res = bn; bn->tsorted = 0; if (bn->tkey) BATkey(BATmirror(bn), FALSE); BBPfix(bn->batCacheid); return GDK_SUCCEED;}#line 414 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/mkey.mx"str MKEYhash_chr(int *ret, chr *v){ CMDhash_chr(ret,v); return MAL_SUCCEED;}str MKEYhash_sht(int *ret, sht *v){ CMDhash_sht(ret,v); return MAL_SUCCEED;}str MKEYhash_int(int *ret, int *v){ CMDhash_int(ret,v); return MAL_SUCCEED;}str MKEYhash_flt(int *ret, flt *v){ CMDhash_flt(ret,v); return MAL_SUCCEED;}str MKEYhash_dbl(int *ret, dbl *v){ CMDhash_dbl(ret,v); return MAL_SUCCEED;}str MKEYhash_lng(int *ret, lng *v){ CMDhash_lng(ret,v); return MAL_SUCCEED;}str MKEYhash_str(int *ret, str *v){ CMDhash_str(ret,*v); return MAL_SUCCEED;}strMKEYrotate(int *res, int *val, int *n){ CMDrotate(res,val,n); return MAL_SUCCEED;}strMKEYhash(MalBlkPtr mb, MalStkPtr stk, InstrPtr p){ int *ret; ptr val; ret= (int*) getArgReference(stk,p,0); val= (ptr) getArgReference(stk,p,1); CMDhash(ret, val, getArgType(mb,p,1)); return MAL_SUCCEED;}strMKEYbulk_rotate_xor_hash(int *ret, int *hid, int *nbits, int *bid){ BAT *hn, *b, *bn=0; if ((hn = BATdescriptor(*hid)) == NULL) { throw(MAL, "mkey.bulk_rotate_xor_hash", "Cannot access descriptor"); } if ((b = BATdescriptor(*bid)) == NULL) { BBPreleaseref(hn->batCacheid); throw(MAL, "mkey.bulk_rotate_xor_hash", "Cannot access descriptor"); } if( CMDbulk_rotate_xor_hash(&bn,hn,nbits,b) == GDK_FAIL){ BBPreleaseref(hn->batCacheid); BBPreleaseref(b->batCacheid); throw(MAL, "mkey.bulk_rotate_xor_hash", "command failed"); } BBPreleaseref(hn->batCacheid); BBPreleaseref(b->batCacheid); *ret= bn->batCacheid; BBPkeepref(bn->batCacheid); return MAL_SUCCEED;}#line 498 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/mkey.mx"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -