str DCselectInsert(int *ret, int *res, int *bid, lng *low, lng *hgh) { BAT *b, *r; lng *readerH, *writerH; lng *readerT, *writerT; BUN size, i; (void) ret; if ((b = BATdescriptor(*bid)) == NULL) throw(MAL, "dc.selectInsert", "Cannot access input BAT"); if ((r = BATdescriptor(*res)) == NULL) throw(MAL, "dc.selectInsert", "Cannot access result BAT"); size = BATcount(b); if (size > BATcapacity(r) - BATcount(r)) { BUN ncap; BUN grows; BUN needed = size - (BATcapacity(r) - BATcount(r)); ncap = BATcapacity(r) + needed; grows = BATgrows(r); if (ncap > grows) grows = ncap; if (BATextend(r, grows) == NULL) throw(MAL, "dc.selectInsert", "Failed to make room for the new values"); } /*printf("in dc.selectInsert size is "OIDFMT,size);*/ writerH = (lng *) Hloc(r, BUNfirst(r)); writerT = (lng *) Tloc(r, BUNfirst(r)); readerH = (lng *) Hloc(b, BUNfirst(b)); readerT = (lng *) Tloc(b, BUNfirst(b)); for (i = 0; i < size; i++) { if (*readerT >= *low && *readerT <= *hgh) { *writerH = *readerH; *writerT = *readerT; writerH++; writerT++; } readerH++; readerT++; } BATsetcount(r, (BUN) (writerT - (lng *) Tloc(r, BUNfirst(r)))); BBPunfix(*bid); BBPunfix(*res); return MAL_SUCCEED; }
static str MATpack2Internal(MalStkPtr stk, InstrPtr p) { int i,*ret; BAT *b, *bn; BUN cap=0; b= BATdescriptor(stk->stk[getArg(p,1)].val.ival); if( b == NULL) throw(MAL, "mat.pack", RUNTIME_OBJECT_MISSING); bn = BATcopy(b, b->htype, b->ttype, TRUE, TRANSIENT); BBPunfix(b->batCacheid); if( bn == NULL) throw(MAL, "mat.pack", MAL_MALLOC_FAIL); for(i = 2; i < p->argc; i++){ b= BATdescriptor(stk->stk[getArg(p,i)].val.ival); if( b == NULL){ BBPreleaseref(bn->batCacheid); throw(MAL, "mat.pack", RUNTIME_OBJECT_MISSING); } cap += BATcount(b); BBPunfix(b->batCacheid); } bn = BATextend(bn, cap); if( bn == NULL) throw(MAL, "mat.pack", RUNTIME_OBJECT_MISSING); for( i = 2; i < p->argc; i++){ b= BATdescriptor(stk->stk[getArg(p,i)].val.ival); if( b == NULL){ BBPreleaseref(bn->batCacheid); throw(MAL, "mat.pack", RUNTIME_OBJECT_MISSING); } BATappend(bn,b,FALSE); BBPunfix(b->batCacheid); } ret= (int*) getArgReference(stk,p,0); BBPkeepref(*ret = bn->batCacheid); return MAL_SUCCEED; }