📄 aggr.mx
字号:
@5: "BUNhloc(b,p)" for (oid) b-head-type, b-head access "&bhsb; bhsb++" for (void) b-head-type @6: BUNtloc(bn,r) BUNtloc(bn,r) &cnt[(*(oid*)h)-min] *dst: count in-place or in cnt-array ?*/@= aggrX3_count3 ALGODEBUG THRprintf(GDKout, "#aggrX3_count3(@1,@2,@3,@4,@5,@6);\n"); if (@1) { /* create tmp. cnt array */ cnt = (int*) GDKmalloc(range*sizeof(int)); memset(cnt, 0, range*sizeof(int)); } if (@2 && BATprepareHash(bn)) { if (@1) GDKfree(cnt); BBPreclaim(bn); return GDK_FAIL; } /* scan b & g, and increment counts in-place or in cnt-array */ base = BUNindex(g, BUNfirst(g)); offset = (ssize_t) (base - g->hseqbase); end = base + BATcount(g); bhsb = b->hseqbase; btt = b->ttype; if (*ignore_nils) { switch(ATOMstorage(btt)) { case TYPE_chr: @:aggrX3_count3_loop(@1,@2,@3,@4,@5,@6,if (!simple_EQ(BUNtloc(b,p),bt_nil,chr)))@ case TYPE_sht: @:aggrX3_count3_loop(@1,@2,@3,@4,@5,@6,if (!simple_EQ(BUNtloc(b,p),bt_nil,sht)))@ case TYPE_int: @:aggrX3_count3_loop(@1,@2,@3,@4,@5,@6,if (!simple_EQ(BUNtloc(b,p),bt_nil,int)))@ case TYPE_lng: @:aggrX3_count3_loop(@1,@2,@3,@4,@5,@6,if (!simple_EQ(BUNtloc(b,p),bt_nil,lng)))@ case TYPE_flt: @:aggrX3_count3_loop(@1,@2,@3,@4,@5,@6,if (!simple_EQ(BUNtloc(b,p),bt_nil,flt)))@ case TYPE_dbl: @:aggrX3_count3_loop(@1,@2,@3,@4,@5,@6,if (!simple_EQ(BUNtloc(b,p),bt_nil,dbl)))@ default: if (b->tvarsized) { @:aggrX3_count3_loop(@1,@2,@3,@4,@5,@6,if (!atom_EQ(BUNtvar(b,p),bt_nil,btt)))@ } else { @:aggrX3_count3_loop(@1,@2,@3,@4,@5,@6,if (!atom_EQ(BUNtloc(b,p),bt_nil,btt)))@ } } } else { switch(ATOMstorage(btt)) { case TYPE_chr: @:aggrX3_count3_loop(@1,@2,@3,@4,@5,@6,)@ case TYPE_sht: @:aggrX3_count3_loop(@1,@2,@3,@4,@5,@6,)@ case TYPE_int: @:aggrX3_count3_loop(@1,@2,@3,@4,@5,@6,)@ case TYPE_lng: @:aggrX3_count3_loop(@1,@2,@3,@4,@5,@6,)@ case TYPE_flt: @:aggrX3_count3_loop(@1,@2,@3,@4,@5,@6,)@ case TYPE_dbl: @:aggrX3_count3_loop(@1,@2,@3,@4,@5,@6,)@ default: if (b->tvarsized) { @:aggrX3_count3_loop(@1,@2,@3,@4,@5,@6,)@ } else { @:aggrX3_count3_loop(@1,@2,@3,@4,@5,@6,)@ } } } if (@1) { /* copy cnt array to final result */ BATloopFast(bn, p, q, xx) { oid h = (*(oid*) BUNh@4(bn,p)) - min; *(int*)BUNtloc(bn, p) = cnt[h]; } GDKfree(cnt); }@c/* aggrX3_count3_loop @7: if (!atom_EQ(BUNt{loc,var}(b,p),bt_nil,btt)) b-tail nil check if (!simple_EQ(BUNtloc(b,p),bt_nil,{chr,sht,int,flt,lng,dbl}))*/@= aggrX3_count3_loop ALGODEBUG THRprintf(GDKout, "#aggrX3_count3_loop(@1,@2,@3,@4,@5,@6,@7);\n"); BATloopFast(b, p, q, xx) { oid v = *(oid*) @5; w = offset + v; if (w >= base && w < end) { oid *h = (oid*) BUNtloc(g, BUNptr(g, w)); @3(r, bn, (oid*)h); if (r) { @7 { int *dst = (int*) @6; (*dst)++; } } } } break;@cintCMDaggrX3_count3(BAT **ret, BAT *b, BAT *g, BAT *e, bit *ignore_nils){ BAT *bn; int zero = 0, *cnt; BUN p, q, r; int xx; size_t range = 0; oid min = 0, max = 0; oid bhsb; size_t base, end, w; ssize_t offset; int btt; ptr bt_nil = ATOMnilptr(b->ttype); ALGODEBUG THRprintf(GDKout, "#CMDaggrX3_count3(b=%s,g=%s,e=%s);\n", BATgetId(b),BATgetId(g),BATgetId(e));/* ERRORcheck((BATcount(b)!=BATcount(g)), "CMDaggrX3_count3: BATs b & g must be of equal size.\n"); */ ERRORcheck((g->htype == TYPE_void) && (g->hseqbase == oid_nil) && (BATcount(g) > 0), "CMDaggrX3_count3: head of BAT g must not be nil.\n"); if ((g->hseqbase == oid_nil) || (!BAThdense(g)) || (!(BAThordered(b) & 1)) || (!g->hkey)) { return CMDaggrX3_count(ret, BATjoin(BATmirror(g), b, oid_nil), e, ignore_nils); } if (e->htype == TYPE_void && b->htype == TYPE_void && g->htype == TYPE_void && g->ttype == TYPE_void) { /* simply return counts with one */ int one = 1; bn = BATconst(b, TYPE_int, &one); *ret = bn; return GDK_SUCCEED; } bn = BATnew(e->htype, TYPE_int, BATcount(e)); if (bn == NULL) return GDK_FAIL; /* init: set all counts to zero and calculate min/max oid */ @:init_result(int)@ range = max - min + 1; /* scan b & g, and calculate counts */ if (e->htype == TYPE_void) { /* void lookup */ if (b->htype == TYPE_void) { @:aggrX3_count3(0,0,BUNfndVOID,var,&bhsb;bhsb++,BUNtloc(bn,r))@ } else { @:aggrX3_count3(0,0,BUNfndVOID,var,BUNhloc(b,p),BUNtloc(bn,r))@ } /* e->htype == TYPE_oid */ } else if (range > SMALL_AGGR_MAX) { /* hash lookup */ if (b->htype == TYPE_void) { @:aggrX3_count3(0,1,HASHfnd_oid,loc,&bhsb;bhsb++,BUNtloc(bn,r))@ } else { @:aggrX3_count3(0,1,HASHfnd_oid,loc,BUNhloc(b,p),BUNtloc(bn,r))@ } } else { /* array lookup */ if (b->htype == TYPE_void) { @:aggrX3_count3(1,0,CHKrange,loc,&bhsb;bhsb++,&cnt[(*(oid*)h)-min])@ } else { @:aggrX3_count3(1,0,CHKrange,loc,BUNhloc(b,p),&cnt[(*(oid*)h)-min])@ } } *ret = bn; return GDK_SUCCEED;}@- WrapperThe remainder is a wrapper around the V4 code base.@c#include "mal.h"#include "mal_exception.h"#ifdef WIN32#ifndef LIBAGGR#define aggr_export extern __declspec(dllimport)#else#define aggr_export extern __declspec(dllexport)#endif#else#define aggr_export extern#endif@-@= AX3sumaggr_export str AX3aggrX3_sum_@1_@3(int *retid, int *bid, int *eid);str AX3aggrX3_sum_@1_@3(int *retid, int *bid, int *eid){ BAT *b, *e; BAT *bn; if( (b= BATdescriptor(*bid)) == NULL ){ throw(MAL, "bbp.sum", "Cannot access descriptor"); } if( (e= BATdescriptor(*eid)) == NULL ){ BBPreleaseref(b->batCacheid); throw(MAL, "bbp.sum", "Cannot access descriptor"); } if( CMDaggrX3_sum_@1_@3(&bn,b,e) == GDK_SUCCEED){ BBPreleaseref(b->batCacheid); BBPreleaseref(e->batCacheid); if (!(bn->batDirty&2)) bn = BATsetaccess(bn, BAT_READ); *retid = bn->batCacheid; BBPkeepref(*retid); return MAL_SUCCEED; } BBPreleaseref(b->batCacheid); BBPreleaseref(e->batCacheid); throw(MAL, "aggrX3_sum.@4","GDKerror");}@-@= AX3prodaggr_export str AX3aggrX3_prod_@1_@3(int *retid, int *bid, int *eid);str AX3aggrX3_prod_@1_@3(int *retid, int *bid, int *eid){ BAT *b, *e, *bn; if( (b= BATdescriptor(*bid)) == NULL ){ throw(MAL, "bbp.prod", "Cannot access descriptor"); } if( (e= BATdescriptor(*eid)) == NULL ){ BBPreleaseref(b->batCacheid); throw(MAL, "bbp.prod", "Cannot access descriptor"); } if( CMDaggrX3_prod_@1_@3(&bn,b,e) == GDK_SUCCEED){ BBPreleaseref(b->batCacheid); BBPreleaseref(e->batCacheid); if (!(bn->batDirty&2)) bn = BATsetaccess(bn, BAT_READ); *retid = bn->batCacheid; BBPkeepref(*retid); return MAL_SUCCEED; } BBPreleaseref(b->batCacheid); BBPreleaseref(e->batCacheid); throw(MAL, "aggrX3_sum.@4","GDKerror");}@-@= AX3sumprod @:AX3sum(@1,@2,@3)@ /* product here */ @:AX3prod(@1,@2,@3)@@c@:AX3sumprod(sht,tloc,sht)@@:AX3sumprod(sht,tloc,int)@@:AX3sumprod(sht,tloc,lng)@@:AX3sumprod(int,tloc,int)@@:AX3sumprod(oid,tloc,int)@@:AX3sumprod(int,tloc,lng)@@:AX3sumprod(lng,tloc,lng)@@:AX3sumprod(flt,tloc,flt)@@:AX3sumprod(flt,tloc,dbl)@@:AX3sumprod(dbl,tloc,dbl)@@-@= AX3arithavgaggr_export str AX3aggrX3_avg_@1(int *retid, int *bid, int *eid);str AX3aggrX3_avg_@1(int *retid, int *bid, int *eid){ BAT *b, *e, *bn; if( (b= BATdescriptor(*bid)) == NULL ){ throw(MAL, "aggr.avg", "Cannot access descriptor"); } if( (e= BATdescriptor(*eid)) == NULL ){ BBPreleaseref(b->batCacheid); throw(MAL, "aggr.avg", "Cannot access descriptor"); } if( CMDaggrX3_avg_@1(&bn,b,e) == GDK_SUCCEED){ BBPreleaseref(b->batCacheid); BBPreleaseref(e->batCacheid); if (!(bn->batDirty&2)) bn = BATsetaccess(bn, BAT_READ); *retid = bn->batCacheid; BBPkeepref(*retid); return MAL_SUCCEED; } BBPreleaseref(b->batCacheid); BBPreleaseref(e->batCacheid); throw(MAL, "aggrX3_avg.@1","GDKerror");}@c@:AX3arithavg(sht,loc)@@:AX3arithavg(int,loc)@@:AX3arithavg(lng,loc)@@:AX3arithavg(flt,loc)@@:AX3arithavg(dbl,loc)@@- "Extremes" (Min & Max)@= AX3extremeaggr_export str AX3aggrX3_@1(int *ret, int *bid, int *eid);str AX3aggrX3_@1(int *ret, int *bid, int *eid){ BAT *b, *e, *bn; if( (b= BATdescriptor(*bid)) == NULL ){ throw(MAL, "aggr.avg", "Cannot access descriptor"); } if( (e= BATdescriptor(*eid)) == NULL ){ BBPreleaseref(b->batCacheid); throw(MAL, "aggr.avg", "Cannot access descriptor"); } if( CMDaggrX3_@1(&bn,b,e) == GDK_SUCCEED){ BBPreleaseref(b->batCacheid); BBPreleaseref(e->batCacheid); if (!(bn->batDirty&2)) bn = BATsetaccess(bn, BAT_READ); *ret = bn->batCacheid; BBPkeepref(*ret); return MAL_SUCCEED; } BBPreleaseref(b->batCacheid); BBPreleaseref(e->batCacheid); throw(MAL, "aggrX3_@1","GDKerror");}@c@:AX3extreme(min,<)@@:AX3extreme(max,>)@@- Count@caggr_export str AX3aggrX3_count(int *retid, int *bid, int *eid, bit *ignore_nils);strAX3aggrX3_count(int *retid, int *bid, int *eid, bit *ignore_nils){ BAT *b, *e, *bn; if ((b = BATdescriptor(*bid)) == NULL) { throw(MAL, "aggr.avg", "Cannot access descriptor"); } if ((e = BATdescriptor(*eid)) == NULL) { BBPreleaseref(b->batCacheid); throw(MAL, "aggr.avg", "Cannot access descriptor"); } if (CMDaggrX3_count(&bn, b, e, ignore_nils) == GDK_SUCCEED) { if (!(bn->batDirty&2)) bn = BATsetaccess(bn, BAT_READ); *retid = bn->batCacheid; BBPkeepref(*retid); BBPreleaseref(b->batCacheid); BBPreleaseref(e->batCacheid); return MAL_SUCCEED; } BBPreleaseref(b->batCacheid); BBPreleaseref(e->batCacheid); throw(MAL, "aggrX3_count", "GDKerror");}@- Size@caggr_export str AX3aggrX3_size(int *retid, int *bid, int *eid);strAX3aggrX3_size(int *retid, int *bid, int *eid){ BAT *b, *e; BAT *bn; if ((b = BATdescriptor(*bid)) == NULL) { throw(MAL, "aggr.avg", "Cannot access descriptor"); } if ((e = BATdescriptor(*eid)) == NULL) { BBPreleaseref(b->batCacheid); throw(MAL, "aggr.avg", "Cannot access descriptor"); } if (CMDaggrX3_size(&bn, b, e) == GDK_SUCCEED) { BBPreleaseref(b->batCacheid); BBPreleaseref(e->batCacheid); if (!(bn->batDirty&2)) bn = BATsetaccess(bn, BAT_READ); *retid = bn->batCacheid; BBPkeepref(*retid); return MAL_SUCCEED; } BBPreleaseref(b->batCacheid); BBPreleaseref(e->batCacheid); throw(MAL, "aggrX3_size", "GDKerror");}@- Sum & Average & Prod @= AX3arithsum3aggr_export str AX3aggrX3_sum3_@1_@2(int *retid,int *bid, int *gid, int *eid);str AX3aggrX3_sum3_@1_@2(int *retid,int *bid, int *gid, int *eid){ BAT *b,*g, *e; BAT *bn; if( (b= BATdescriptor(*bid)) == NULL ){ throw(MAL, "aggr.avg", "Cannot access descriptor"); } if( (e= BATdescriptor(*eid)) == NULL ){ BBPreleaseref(b->batCacheid); throw(MAL, "aggr.avg", "Cannot access descriptor"); } if( (g= BATdescriptor(*gid)) == NULL ){ BBPreleaseref(e->batCacheid); BBPreleaseref(b->batCacheid); throw(MAL, "aggr.avg", "Cannot access descriptor"); } if( CMDaggrX3_sum3_@1_@2(&bn,b,g,e) == GDK_SUCCEED){ BBPreleaseref(b->batCacheid); BBPreleaseref(e->batCacheid); BBPreleaseref(g->batCacheid); if (!(bn->batDirty&2)) bn = BATsetaccess(bn, BAT_READ); *retid = bn->batCacheid; BBPkeepref(*retid); return MAL_SUCCEED; } BBPreleaseref(b->batCacheid); BBPreleaseref(e->batCacheid); BBPreleaseref(g->batCacheid); throw(MAL, "aggrX3_sum3","GDKerror");}@-@= AX3prod3aggr_export str AX3aggrX3_prod3_@1_@2(int *retid,int *bid, int *gid, int *eid);str AX3aggrX3_prod3_@1_@2(int *retid,int *bid, int *gid, int *eid){ BAT *b,*g, *e; BAT *bn; if ((b = BATdescriptor(*bid)) == NULL) throw(MAL, "aggr.avg", "Cannot access descriptor"); if( (e= BATdescriptor(*eid)) == NULL ){ BBPreleaseref(b->batCacheid); throw(MAL, "aggr.avg", "Cannot access descriptor"); } if( (g= BATdescriptor(*gid)) == NULL ){ BBPreleaseref(e->batCacheid); BBPreleaseref(b->batCacheid); throw(MAL, "aggr.avg", "Cannot access descriptor"); } if( CMDaggrX3_prod3_@1_@2(&bn,b,g,e) == GDK_SUCCEED){ BBPreleaseref(b->batCacheid); BBPreleaseref(e->batCacheid); BBPreleaseref(g->batCacheid); if (!(bn->batDirty&2)) bn = BATsetaccess(bn, BAT_READ); *retid = bn->batCacheid; BBPkeepref(*retid); return MAL_SUCCEED; } BBPreleaseref(b->batCacheid); BBPreleaseref(e->batCacheid); BBPreleaseref(g->batCacheid); throw(MAL, "aggrX3_prod3","GDKerror");}@-@= AX3sumprod3@:AX3arithsum3(@1,@2)@@:AX3prod3(@1,@2)@@c@:AX3sumprod3(sht,sht)@@:AX3sumprod3(sht,int)@@:AX3sumprod3(sht,lng)@@:AX3sumprod3(int,int)@@:AX3sumprod3(oid,int)@@:AX3sumprod3(int,lng)@@:AX3sumprod3(lng,lng)@@:AX3sumprod3(flt,flt)@@:AX3sumprod3(flt,dbl)@@:AX3sumprod3(dbl,dbl)@@= AX3arithavg3aggr_export str AX3aggrX3_avg3_@1(int *retid,int *bid, int *gid, int *eid);str AX3
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -