📄 bat5.mx
字号:
int bid = BBPindex(input); if (bid) { *res = BBP_lastused(bid) & 0x7fffffff; } return GDK_SUCCEED;}intCMDsave(bit *res, str input){ bat bid = BBPindex(input); BAT *b; *res = FALSE; if (bid) { BBPfix(bid); b = BBP_cache(bid); if (b && BATdirty(b)) { if (BBPsave(b) == 0) *res = TRUE; } BBPunfix(bid); } return GDK_SUCCEED;}@= change_heap{ if (@2) { int mode = (@2)->storage; if (mode == STORE_MMAP && (@2)->filename == NULL) mode = STORE_MEM; if (mode == STORE_PRIV) mode = STORE_MMAP; if (*@1 == int_nil || *@1 == mode) { *@1 = -1; } }}@cintCMDmmap(BAT **r, BAT *b, int *bns, int *hhp, int *thp){ @:change_heap(bns,b->batBuns)@ @:change_heap(hhp,b->hheap)@ @:change_heap(thp,b->theap)@ if (BATmmap(*r = b, *bns, *hhp, *thp) == 0) { BBPfix(b->batCacheid); return GDK_SUCCEED; } return GDK_FAIL;}intCMDmadvise(BAT **r, BAT *b, int *bns, int *hhp, int *thp){ BBPfix(b->batCacheid); return BATmadvise(*r = b, (*bns == int_nil) ? -1 : *bns, (*hhp == int_nil) ? -1 : *hhp, (*thp == int_nil) ? -1 : *thp) ? GDK_FAIL : GDK_SUCCEED;}/* ITERATIONS ARE DEFINED ELSEWHERE */intCMDget_seqbase(oid *o, BAT *b){ *o = b->hseqbase; return GDK_SUCCEED;}intCMDset_seqbase(BAT **r, BAT *b, oid *o){ BATseqbase(*r = b, *o); BBPfix(b->batCacheid); return GDK_SUCCEED;}@- WrappingThe remainder contains the wrapper code over the version 4@+ InformationFunctionsIn most cases we pass a BAT identifier, which should be unifiedwith a BAT descriptor. Upon failure we can simply abort the function.The logical head type :oid is mapped to a TYPE_voidwith sequenceBase. It represents the old fashioned :vid@cchar *BKCnewBATint(int *res, int *ht, int *tt, int *cap){ BAT *b; if( *ht == TYPE_oid){ int tpe= TYPE_void; if (CMDnew(&b, &tpe, tt, cap) == GDK_SUCCEED) { oid o= 0; BATseqbase(b, o); *res = b->batCacheid; BBPkeepref(*res); return MAL_SUCCEED; } } else if (CMDnew(&b, ht, tt, cap) == GDK_SUCCEED) { *res = b->batCacheid; BBPkeepref(*res); return MAL_SUCCEED; } throw(MAL, "bat.new", "GDKerror in BAT construction");}strBKCnewBATlng(int *res, int *ht, int *tt, lng *cap){ BAT *b; if( *ht == TYPE_oid){ int tpe= TYPE_void; if (CMDnew_lng(&b, &tpe, tt, cap) == GDK_SUCCEED) { oid o=0; BATseqbase(b, o); *res = b->batCacheid; BBPkeepref(*res); return MAL_SUCCEED; } } else if (CMDnew_lng(&b, ht, tt, cap) == GDK_SUCCEED) { *res = b->batCacheid; BBPkeepref(*res); return MAL_SUCCEED; } throw(MAL, "bat.new", "GDKerror in BAT construction");}strBKCnewBat(int *res, int *ht, int *tt){ lng cap = 0; return BKCnewBATlng(res, ht, tt, &cap);}strBKCreverse(int *ret, int *bid){ BAT *b, *bn = NULL; if ((b = BATdescriptor(*bid)) == NULL) { throw(MAL, "bat.reverse", "Cannot access descriptor"); } CMDreverse(&bn, b); BBPreleaseref(b->batCacheid); if (bn) { *ret = bn->batCacheid; BBPkeepref(bn->batCacheid); return MAL_SUCCEED; } throw(MAL, "bat.reverse", "GDKerror");}strBKCmirror(int *ret, int *bid){ BAT *b, *bn = NULL; if ((b = BATdescriptor(*bid)) == NULL) { throw(MAL, "bat.mirror", "Cannot access descriptor"); } if (CMDmirror(&bn, b) == GDK_SUCCEED) { *ret = bn->batCacheid; BBPkeepref(*ret); BBPreleaseref(b->batCacheid); return MAL_SUCCEED; } *ret = 0; BBPreleaseref(b->batCacheid); throw(MAL, "bat.mirror", "GDKerror");}strBKCconvert(int *ret, int *bid){ BAT *b; if ((b = BATdescriptor(*bid)) == NULL) { throw(MAL, "bat.convert", "Cannot access descriptor"); } if (BATconvert(b, CONV_HTON) == NULL) { BBPreleaseref(b->batCacheid); throw(MAL, "bat.convert", "Failed"); } *ret = b->batCacheid; BBPkeepref(*ret); return MAL_SUCCEED;}strBKCrevert(int *ret, int *bid){ BAT *b; if ((b = BATdescriptor(*bid)) == NULL) { throw(MAL, "bat.revert", "Cannot access descriptor"); } if (BATrevert(b) != NULL) { *ret = b->batCacheid; BBPkeepref(b->batCacheid); return MAL_SUCCEED; } BBPreleaseref(b->batCacheid); throw(MAL, "bat.revert", "GDKerror");}strBKCorder(int *ret, int *bid){ BAT *b; if ((b = BATdescriptor(*bid)) == NULL) { throw(MAL, "bat.order", "Cannot access descriptor"); } if (BATorder(b) != NULL) { *ret = b->batCacheid; BBPkeepref(b->batCacheid); return MAL_SUCCEED; } BBPreleaseref(b->batCacheid); throw(MAL, "bat.order", "GDKerror");}strBKCorder_rev(int *ret, int *bid){ BAT *b; (void) ret; if ((b = BATdescriptor(*bid)) == NULL) { throw(MAL, "bat.order_rev", "Cannot access descriptor"); } if (BATorder_rev(b) != NULL) { *ret = b->batCacheid; BBPkeepref(b->batCacheid); return MAL_SUCCEED; } BBPreleaseref(b->batCacheid); throw(MAL, "bat.order", "GDKerror");}@-Insertions into the BAT may involve void types (=no storage required)These cases should actually be captured during BUNins, because theymay emerge internally as well.@= void_insertbunif (b->@1type == TYPE_void && *(oid*) @1 != oid_nil && *(oid*) @1 != (b->@1seqbase + BUNgetpos(b, BUNlast(b)))){printf("val %d seqbase %d pos %d\n", *(oid*)@1, b->@1seqbase, BUNgetpos(b, BUNlast(b)) ); throw(MAL, "bat.insert", " insert non-nil values in a void column.");}@cchar *BKCinsert_void_bun(int *r, int *bid, ptr t){ BAT *b; (void) r; if ((b = BATdescriptor(*bid)) == NULL) { throw(MAL, "bat.insert", "Cannot access descriptor"); } @:derefStr(b,t,t)@ BUNappend(b, t,FALSE); BBPreleaseref(b->batCacheid); return MAL_SUCCEED;}char *BKCinsert_bun(int *r, int *bid, ptr h, ptr t){ BAT *b; (void) r; if ((b = BATdescriptor(*bid)) == NULL) { throw(MAL, "bat.insert", "Cannot access descriptor"); } @:derefStr(b,h,h)@ @:derefStr(b,t,t)@ BUNins(b, h, t,FALSE); BBPreleaseref(b->batCacheid); return MAL_SUCCEED;}char *BKCinsert_bun_force(int *r, int *bid, ptr h, ptr t, bit *force){ BAT *b; (void) r; if ((b = BATdescriptor(*bid)) == NULL) { throw(MAL, "bat.insert", "Cannot access descriptor"); } @:derefStr(b,h,h)@ @:derefStr(b,t,t)@ BUNins(b, h, t, *force); BBPreleaseref(b->batCacheid); return MAL_SUCCEED;}char *BKCinsert_bun_oid_any(int *r, int *bid, ptr h, ptr t){ BAT *b; (void) r; if ((b = BATdescriptor(*bid)) == NULL) { throw(MAL, "bat.insert", "Cannot access descriptor"); } /* tail is not(!) a string */ BUNins(b, h, t,FALSE); BBPreleaseref(b->batCacheid); return MAL_SUCCEED;}char *BKCinsert_bun_int_int(int *r, int *bid, int *h, int *t){ BAT *b; (void) r; if ((b = BATdescriptor(*bid)) == NULL) { throw(MAL, "bat.insert", "Cannot access descriptor"); } BUNins(b, h, t,FALSE); BBPreleaseref(b->batCacheid); return MAL_SUCCEED;}char *BKCinsert_bun_oid_str(int *r, int *bid, ptr h, ptr t){ BAT *b; (void) r; if ((b = BATdescriptor(*bid)) == NULL) { throw(MAL, "bat.insert", "Cannot access descriptor"); } @:derefStr(b,t,t)@ BUNins(b, h, t,FALSE); BBPreleaseref(b->batCacheid); return MAL_SUCCEED;}strBKCinsert_bat(int *r, int *bid, int *sid){ BAT *b, *s; (void) r; if ((b = BATdescriptor(*bid)) == NULL) { throw(MAL, "bat.insert", "Cannot access descriptor"); } if ((s = BATdescriptor(*sid)) == NULL) { BBPreleaseref(b->batCacheid); throw(MAL, "bat.insert", "Cannot access descriptor"); } if (BATins(b, s,FALSE) == NULL) { BBPreleaseref(b->batCacheid); BBPreleaseref(s->batCacheid); throw(MAL, "bat.insert", "Failed"); } BBPreleaseref(b->batCacheid); BBPreleaseref(s->batCacheid); return MAL_SUCCEED;}strBKCinsert_bat_force(int *r, int *bid, int *sid, bit *force){ BAT *b, *s; (void) r; if ((b = BATdescriptor(*bid)) == NULL) { throw(MAL, "bat.insert", "Cannot access descriptor"); } if ((s = BATdescriptor(*sid)) == NULL) { BBPreleaseref(b->batCacheid); throw(MAL, "bat.insert", "Cannot access descriptor"); } if (BATins(b, s, *force) == NULL) { BBPreleaseref(b->batCacheid); BBPreleaseref(s->batCacheid); throw(MAL, "bat.insert", "Failed"); } BBPreleaseref(b->batCacheid); BBPreleaseref(s->batCacheid); return MAL_SUCCEED;}strBKCreplace_bun(int *r, int *bid, ptr h, ptr t){ BAT *b; (void) r; if ((b = BATdescriptor(*bid)) == NULL) { throw(MAL, "bat.replace", "Cannot access descriptor"); } @:derefStr(b,h,h)@ @:derefStr(b,t,t)@ if (BUNreplace(b, h, t, 0) == NULL) { BBPreleaseref(b->batCacheid); throw(MAL, "bat.replace", "BUNreplaceFailed"); } BBPreleaseref(b->batCacheid); return MAL_SUCCEED;}strBKCreplace_bat(int *r, int *bid, int *sid){ BAT *b, *s; (void) r; if ((b = BATdescriptor(*bid)) == NULL) { throw(MAL, "bat.replace", "Cannot access descriptor"); } if ((s = BATdescriptor(*sid)) == NULL) { BBPreleaseref(b->batCacheid); throw(MAL, "bat.replace", "Cannot access descriptor"); } if (BATreplace(b, s, 0) != NULL) { BBPreleaseref(b->batCacheid); BBPreleaseref(s->batCacheid); return MAL_SUCCEED; } BBPreleaseref(b->batCacheid); BBPreleaseref(s->batCacheid); throw(MAL, "bat.replace_bat", "GDKerror");}strBKCreplace_bun_force(int *r, int *bid, ptr h, ptr t, bit *force){ BAT *b; (void) r; if ((b = BATdescriptor(*bid)) == NULL) { throw(MAL, "bat.replace", "Cannot access descriptor"); } @:derefStr(b,h,h)@ @:derefStr(b,t,t)@ if (BUNreplace(b, h, t, *force) == NULL) { BBPreleaseref(b->batCacheid); throw(MAL, "bat.replace", "BUNreplaceFailed"); } BBPreleaseref(b->batCacheid); return MAL_SUCCEED;}strBKCreplace_bat_force(int *r, int *bid, int *sid, bit *force){ BAT *b, *s; (void) r; if ((b = BATdescriptor(*bid)) == NULL) { throw(MAL, "bat.replace", "Cannot access descriptor"); } if ((s = BATdescriptor(*sid)) == NULL) { BBPreleaseref(b->batCacheid); throw(MAL, "bat.replace", "Cannot access descriptor"); } if (BATreplace(b, s, *force) != NULL) { BBPreleaseref(b->batCacheid); BBPreleaseref(s->batCacheid); return MAL_SUCCEED; } BBPreleaseref(b->batCacheid); BBPreleaseref(s->batCacheid); throw(MAL, "bat.replace_bat", "GDKerror");}char *BKCdelete_bun(int *r, int *bid, ptr h, ptr t){ BAT *b; (void) r; if ((b = BATdescriptor(*bid)) == NULL) { throw(MAL, "bat.delete", "Cannot access descriptor"); } @:derefStr(b,h,h)@ @:derefStr(b,t,t)@ if (BUNdel(b, h, t,FALSE) != NULL) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -