test_case(p2, lessthan) { bool a[8], b[8]; to_bits8(a, 11); to_bits8(b, 24); assert_true(lessthan(a, b)); assert_false(lessthan(b, a)); assert_false(lessthan(a, a)); }
void setRegistryValue(bool registryNum[8], bool value[8]) { try{ bool* output = new bool[8]; bool tmpCheck = 0; bool* low = new bool[8]; bool* high = new bool[8]; if ( Eightto1bit(tmpCheck, lessthan(output, registryNum, low))) throw 10; if ( Eightto1bit(tmpCheck, greaterthan(output, registryNum, high))) throw 10; value[0] = registry[to_int8(registryNum)][0]; value[1] = registry[to_int8(registryNum)][1]; value[2] = registry[to_int8(registryNum)][2]; value[3] = registry[to_int8(registryNum)][3]; value[4] = registry[to_int8(registryNum)][4]; value[5] = registry[to_int8(registryNum)][5]; value[6] = registry[to_int8(registryNum)][6]; value[7] = registry[to_int8(registryNum)][7]; } catch (int e) { std::cout<<"Reg("; printValueInDecimal(registryNum); std::cout<<") = "; printValue(registryNum); std::cout<<'\n'; } }
/** * Internal method to insert into a subtree. * x is the item to insert. * t is the node that roots the tree. * Set the new root. */ void BinarySearchTree::insertInternal (Customer * x, BinaryNode * &t) { if (t == NULL) t = new BinaryNode (x, NULL, NULL); else if (lessthan (const_cast < Customer * >(x), const_cast < Customer * >(t->element))) insertInternal (x, t->left); else if (lessthan (const_cast < Customer * >(t->element), const_cast < Customer * >(x))) insertInternal (x, t->right); else { throw InsertException (x); // Duplicate; } }
void add(forensic *any, int *a) { static int vis=0; hapnode *after,*before,*tmp; vis +=1; if (any->first==NULL) { /* none present yet */ any->first = newhapnode(a,any->nloc,vis); any->nhap=1; return; } else if (lessthan(a,any->first->haptype,any->nloc)) { /* before the first */ tmp=newhapnode(a,any->nloc,vis); tmp->next=any->first; any->first=tmp; any->nhap+=1; return; } else if (equals(a,any->first->haptype,any->nloc)) { /* equal to the first */ any->first->count +=1.0; if (vis-any->first->last_visit>1) any->first->nvisits +=1; any->first->last_visit=vis; return; } before=any->first; after=any->first->next; for (;;) { if (after==NULL) { /* after the end */ tmp = newhapnode(a,any->nloc,vis); before->next=tmp; any->nhap+=1; return; } else if (lessthan(a,after->haptype,any->nloc)) { tmp=newhapnode(a,any->nloc,vis); tmp->next=after; before->next=tmp; any->nhap+=1; return; } else if (equals(a,after->haptype,any->nloc)) { after->count +=1.0; if (vis-after->last_visit>1) after->nvisits +=1; after->last_visit=vis; return; } before=after; after=after->next; } }
//Binary Search - return index of key in deck, or -1 int BinSearch(Card key, Card deck[], uint beginning, uint end) { //Sanity Check if (end < beginning) return -1; //Do I only have one? if (end == beginning) { if(equal(key,deck[beginning])) return beginning; else return -1; } //Check middle item int middle = (end-beginning)/2 + beginning; if (equal(key,deck[middle])) return middle; //Not here. Recurse to find it in one of my halves if(lessthan(key,deck[middle])) return BinSearch(key,deck,beginning,middle-1); return BinSearch(key,deck,middle+1,end); }
int fun(){ int i,j; int t; int sum = 0; for(i=0;i<pos;i++){ mark[i] = box[i].h; for(j=i-1;j>=0;j--){ if(lessthan(&box[i], &box[j])){ t = box[i].h + mark[j]; if(mark[i] < t){ mark[i] = t; } } } if(mark[i] > sum) sum = mark[i]; } return sum; }
struct node * merge(struct node * a, struct node * b) { struct node * temp = (struct node *)malloc(sizeof(struct node)); struct node * cur = temp; while(a != NULL && b != NULL) { if(lessthan(a,b)) { cur->next = a; a = a->next; } else { cur->next = b; b = b->next; } cur = cur->next; } if(a == NULL) cur->next = b; else cur->next = a; return temp->next; }
std::pair<bool, ByteOffset> find_bed_range(FILE* qfile, TargetIter titer, TargetIter teof, Op op) { extract_details::TargetBedType reference; extract_details::QueryBedType last, current; Bed::Overlapping overlap, lessthan, greaterthan; // any overlap ByteOffset prev_pos = 0, cur_pos = 0, start_pos = 0, end_pos = 0; extract_details::MType bounds; cur_pos = std::ftell(qfile); // may not be start of file if, for ex., qfile has headers we skipped std::fseek(qfile, 0, SEEK_END); // apparently dangerous on some platforms in binary mode -> padded nulls; const ByteOffset at_end = std::ftell(qfile); // I'll assume msft is the problem until I know better std::fseek(qfile, cur_pos, SEEK_SET); prev_pos = cur_pos; std::iterator_traits<FILE*>::difference_type count, step; bool didWork = false, first = true, donequery = false; while ( titer != teof ) { extract_details::TargetBedType* const refelement = *titer++; if ( donequery ) { // read through and delete items in [titer,teof) for posterity delete refelement; continue; } else if ( !first && (greaterthan(&last, refelement) > 0) ) { // last lower_bound is still applicable delete refelement; continue; } // only use reference where you need to compare to starting base. Otherwise, use refelement. reference = *refelement; reference.end(reference.start()+1); start_pos = std::ftell(qfile); while ( true ) { extract_details::MType::iterator miter = bounds.upper_bound(*refelement); // define end_pos if ( miter == bounds.end() ) { end_pos = at_end; bounds.clear(); break; } else { // it's possible that miter->first and refelement overlap but are not picked up in // bounds.upper_bound() search b/c bounds is ordered by the analog of "<", where // start coord takes precedence. Consider when refelement is less than miter->first // but refelement->end() > miter->first.start(). In such a case miter->first would // not be a proper upper bound. Remove it and try again. bounds.erase(bounds.begin(), miter); end_pos = miter->second; if ( extract_details::check_overlap(refelement, &miter->first) ) bounds.erase(miter); else break; } } // while count = end_pos - start_pos; // how many bytes between positions didWork = false; while ( count > 0 ) { std::fseek(qfile, start_pos, SEEK_SET); step = count/2; std::fseek(qfile, step, SEEK_CUR); // find beginning of current line while ( std::ftell(qfile) != start_pos ) { if ( static_cast<char>(std::fgetc(qfile)) != '\n' ) { std::fseek(qfile, -2, SEEK_CUR); } else { break; } } // while // read in the line; incrementing to start of next QueryBedType element. prev_pos = std::ftell(qfile); current.readline(qfile); cur_pos = std::ftell(qfile); bounds.insert(std::make_pair(current, prev_pos)); // compare 'current' to starting base if ( lessthan(¤t, &reference) < 0 ) { count = (end_pos - cur_pos); start_pos = cur_pos; if ( 0 == count ) { if ( end_pos != at_end ) { prev_pos = cur_pos; current.readline(qfile); cur_pos = std::ftell(qfile); bounds.insert(std::make_pair(current, prev_pos)); } else { prev_pos = at_end; } } } else { count = (prev_pos - start_pos); end_pos = prev_pos; } didWork = true; } // while // spit elements in range if ( didWork ) { while ( prev_pos != at_end && extract_details::check_overlap(¤t, refelement) ) { op(¤t); prev_pos = std::ftell(qfile); if ( prev_pos != at_end ) current.readline(qfile); } // while } if ( refelement ) delete refelement; std::fseek(qfile, prev_pos, SEEK_SET); // because start_pos = std::ftell(qfile); on next go-around if ( prev_pos == at_end ) donequery = true; last = current; first = false; } // while return std::make_pair(!first, prev_pos); }
int main(int argc, char **argv) { char *outputName = 0L; uint32 outputIndex = 0; uint32 inputsLen = 0; char *inputs[8192]; uint64 memoryLimit = 1024 * 1024 * 1024; int arg=1; int err=0; while (arg < argc) { if (strncmp(argv[arg], "-memory", 2) == 0) { memoryLimit = strtouint64(argv[++arg], 0L) * 1024 * 1024; } else if (strncmp(argv[arg], "-output", 2) == 0) { outputName = argv[++arg]; } else { if (tapperResultFile::validResultFile(argv[arg]) == false) { fprintf(stderr, "Didn't find tapperResultFile '%s'\n", argv[arg]); err++; } else { inputs[inputsLen++] = argv[arg]; } } arg++; } if ((err) || (inputsLen == 0) || (outputName == 0L)) { fprintf(stderr, "usage: %s [-memory X (MB)] -output prefix input ....\n", argv[0]); exit(1); } { uint32 aliMax = memoryLimit / sizeof(tapperAlignment); uint32 aliLen = 0; tapperAlignment *ali = new tapperAlignment [aliMax]; fprintf(stderr, "Can fit "uint32FMT" alignments into "uint64FMT" bytes memory; "uint32FMT" bytes each.\n", aliMax, memoryLimit, (uint32)sizeof(tapperAlignment)); speedCounter S(" %10.0f results (%8.0f results/sec)\r", 1, 100000, true); for (uint32 inputsIdx=0; inputsIdx<inputsLen; inputsIdx++) { tapperResultFile *inp = new tapperResultFile(inputs[inputsIdx], 'r'); tapperResult *res = new tapperResult; while (inp->read(res)) { // Sort and dump if the next result has too many alignments. // if (aliMax < aliLen + (res->idx._numFrag + res->idx._numFragSingleton + res->idx._numFragTangled + res->idx._numMated * 2)) { aliLen = sortAndDump(ali, aliLen, outputName, outputIndex); } aliLen = saveFrag(ali, aliLen, res, res->idx._numFrag, res->frag); aliLen = saveFrag(ali, aliLen, res, res->idx._numFragSingleton, res->sing); aliLen = saveFrag(ali, aliLen, res, res->idx._numFragTangled, res->tali); aliLen = saveMate(ali, aliLen, res); S.tick(); } S.finish(); delete inp; delete res; } aliLen = sortAndDump(ali, aliLen, outputName, outputIndex); delete [] ali; } // // Now the merge. // { char filename[FILENAME_MAX]; tapperAlignment *ali = new tapperAlignment [outputIndex]; recordFile **inp = new recordFile * [outputIndex]; recordFile *out = 0L; bool stillMore = true; uint32 minidx = 0; tapperAlignmentPositionCompare lessthan; for (uint32 x=0; x<outputIndex; x++) { sprintf(filename, "%s."uint32FMTW(03)".tapperAlignment", outputName, x); inp[x] = new recordFile(filename, 0, sizeof(tapperAlignment), 'r'); inp[x]->getRecord(ali + x); } sprintf(filename, "%s.tapperAlignment", outputName); out = new recordFile(filename, 0, sizeof(tapperAlignment), 'w'); while (stillMore) { // Compare all against the current default minidx, pick the // smallest alignment currently loaded. for (uint32 x=0; x<outputIndex; x++) if ((x != minidx) && (inp[x] != 0L) && (lessthan(ali[x], ali[minidx]))) minidx = x; // Dump it. out->putRecord(ali + minidx); // Read the next record. If no next record, close the file, // and pick a new default minidx if (inp[minidx]->getRecord(ali + minidx) == 0) { delete inp[minidx]; inp[minidx] = 0L; stillMore = false; for (uint32 x=0; x<outputIndex; x++) if (inp[x] != 0L) { minidx = x; stillMore = true; } } } delete out; for (uint32 x=0; x<outputIndex; x++) { assert(inp[x] == 0L); sprintf(filename, "%s."uint32FMTW(03)".tapperAlignment", outputName, x); unlink(filename); } delete [] inp; delete [] ali; } exit(0); }
static void ktap_execute(ktap_state *ks) { int exec_count = 0; ktap_callinfo *ci; ktap_lclosure *cl; ktap_value *k; unsigned int instr, opcode; StkId base; /* stack pointer */ StkId ra; /* register pointer */ int res, nresults; /* temp varible */ ci = ks->ci; newframe: cl = CLVALUE(ci->func); k = cl->p->k; base = ci->u.l.base; mainloop: /* main loop of interpreter */ /* dead loop detaction */ if (exec_count++ == 10000) { if (G(ks)->mainthread != ks) { kp_error(ks, "non-mainthread executing too much, " "please try to enlarge execution limit\n"); return; } cond_resched(); if (signal_pending(current)) { flush_signals(current); return; } exec_count = 0; } instr = *(ci->u.l.savedpc++); opcode = GET_OPCODE(instr); /* ra is target register */ ra = RA(instr); switch (opcode) { case OP_MOVE: setobj(ra, base + GETARG_B(instr)); break; case OP_LOADK: setobj(ra, k + GETARG_Bx(instr)); break; case OP_LOADKX: setobj(ra, k + GETARG_Ax(*ci->u.l.savedpc++)); break; case OP_LOADBOOL: setbvalue(ra, GETARG_B(instr)); if (GETARG_C(instr)) ci->u.l.savedpc++; break; case OP_LOADNIL: { int b = GETARG_B(instr); do { setnilvalue(ra++); } while (b--); break; } case OP_GETUPVAL: { int b = GETARG_B(instr); setobj(ra, cl->upvals[b]->v); break; } case OP_GETTABUP: { int b = GETARG_B(instr); gettable(ks, cl->upvals[b]->v, RKC(instr), ra); base = ci->u.l.base; break; } case OP_GETTABLE: gettable(ks, RB(instr), RKC(instr), ra); base = ci->u.l.base; break; case OP_SETTABUP: { int a = GETARG_A(instr); settable(ks, cl->upvals[a]->v, RKB(instr), RKC(instr)); base = ci->u.l.base; break; } case OP_SETUPVAL: { ktap_upval *uv = cl->upvals[GETARG_B(instr)]; setobj(uv->v, ra); break; } case OP_SETTABLE: settable(ks, ra, RKB(instr), RKC(instr)); base = ci->u.l.base; break; case OP_NEWTABLE: { int b = GETARG_B(instr); int c = GETARG_C(instr); ktap_table *t = kp_table_new(ks); sethvalue(ra, t); if (b != 0 || c != 0) kp_table_resize(ks, t, fb2int(b), fb2int(c)); break; } case OP_SELF: { StkId rb = RB(instr); setobj(ra+1, rb); gettable(ks, rb, RKC(instr), ra); base = ci->u.l.base; break; } case OP_ADD: arith_op(ks, NUMADD); break; case OP_SUB: arith_op(ks, NUMSUB); break; case OP_MUL: arith_op(ks, NUMMUL); break; case OP_DIV: /* divide 0 checking */ if (!nvalue(RKC(instr))) { kp_error(ks, "divide 0 arith operation\n"); return; } arith_op(ks, NUMDIV); break; case OP_MOD: /* divide 0 checking */ if (!nvalue(RKC(instr))) { kp_error(ks, "mod 0 arith operation\n"); return; } arith_op(ks, NUMMOD); break; case OP_POW: kp_error(ks, "ktap don't support pow arith in kernel\n"); return; case OP_UNM: { ktap_value *rb = RB(instr); if (ttisnumber(rb)) { ktap_number nb = nvalue(rb); setnvalue(ra, NUMUNM(nb)); } break; } case OP_NOT: res = isfalse(RB(instr)); setbvalue(ra, res); break; case OP_LEN: { int len = kp_objlen(ks, RB(instr)); if (len < 0) return; setnvalue(ra, len); break; } case OP_CONCAT: { int b = GETARG_B(instr); int c = GETARG_C(instr); ktap_concat(ks, b, c); break; } case OP_JMP: dojump(ci, instr, 0); break; case OP_EQ: { ktap_value *rb = RKB(instr); ktap_value *rc = RKC(instr); if ((int)equalobj(ks, rb, rc) != GETARG_A(instr)) ci->u.l.savedpc++; else donextjump(ci); base = ci->u.l.base; break; } case OP_LT: if (lessthan(ks, RKB(instr), RKC(instr)) != GETARG_A(instr)) ci->u.l.savedpc++; else donextjump(ci); base = ci->u.l.base; break; case OP_LE: if (lessequal(ks, RKB(instr), RKC(instr)) != GETARG_A(instr)) ci->u.l.savedpc++; else donextjump(ci); base = ci->u.l.base; break; case OP_TEST: if (GETARG_C(instr) ? isfalse(ra) : !isfalse(ra)) ci->u.l.savedpc++; else donextjump(ci); break; case OP_TESTSET: { ktap_value *rb = RB(instr); if (GETARG_C(instr) ? isfalse(rb) : !isfalse(rb)) ci->u.l.savedpc++; else { setobj(ra, rb); donextjump(ci); } break; } case OP_CALL: { int b = GETARG_B(instr); int ret; nresults = GETARG_C(instr) - 1; if (b != 0) ks->top = ra + b; ret = precall(ks, ra, nresults); if (ret) { /* C function */ if (nresults >= 0) ks->top = ci->top; base = ci->u.l.base; break; } else { /* ktap function */ ci = ks->ci; /* this flag is used for return time, see OP_RETURN */ ci->callstatus |= CIST_REENTRY; goto newframe; } break; } case OP_TAILCALL: { int b = GETARG_B(instr); if (b != 0) ks->top = ra+b; if (precall(ks, ra, -1)) /* C function? */ base = ci->u.l.base; else { int aux; /* * tail call: put called frame (n) in place of * caller one (o) */ ktap_callinfo *nci = ks->ci; /* called frame */ ktap_callinfo *oci = nci->prev; /* caller frame */ StkId nfunc = nci->func; /* called function */ StkId ofunc = oci->func; /* caller function */ /* last stack slot filled by 'precall' */ StkId lim = nci->u.l.base + CLVALUE(nfunc)->p->numparams; /* close all upvalues from previous call */ if (cl->p->sizep > 0) function_close(ks, oci->u.l.base); /* move new frame into old one */ for (aux = 0; nfunc + aux < lim; aux++) setobj(ofunc + aux, nfunc + aux); /* correct base */ oci->u.l.base = ofunc + (nci->u.l.base - nfunc); /* correct top */ oci->top = ks->top = ofunc + (ks->top - nfunc); oci->u.l.savedpc = nci->u.l.savedpc; /* remove new frame */ ci = ks->ci = oci; /* restart ktap_execute over new ktap function */ goto newframe; } break; } case OP_RETURN: { int b = GETARG_B(instr); if (b != 0) ks->top = ra+b-1; if (cl->p->sizep > 0) function_close(ks, base); b = poscall(ks, ra); /* if it's called from external invocation, just return */ if (!(ci->callstatus & CIST_REENTRY)) return; ci = ks->ci; if (b) ks->top = ci->top; goto newframe; } case OP_FORLOOP: { ktap_number step = nvalue(ra+2); /* increment index */ ktap_number idx = NUMADD(nvalue(ra), step); ktap_number limit = nvalue(ra+1); if (NUMLT(0, step) ? NUMLE(idx, limit) : NUMLE(limit, idx)) { ci->u.l.savedpc += GETARG_sBx(instr); /* jump back */ setnvalue(ra, idx); /* update internal index... */ setnvalue(ra+3, idx); /* ...and external index */ } break; } case OP_FORPREP: { const ktap_value *init = ra; const ktap_value *plimit = ra + 1; const ktap_value *pstep = ra + 2; if (!ktap_tonumber(init, ra)) { kp_error(ks, KTAP_QL("for") " initial value must be a number\n"); return; } else if (!ktap_tonumber(plimit, ra + 1)) { kp_error(ks, KTAP_QL("for") " limit must be a number\n"); return; } else if (!ktap_tonumber(pstep, ra + 2)) { kp_error(ks, KTAP_QL("for") " step must be a number\n"); return; } setnvalue(ra, NUMSUB(nvalue(ra), nvalue(pstep))); ci->u.l.savedpc += GETARG_sBx(instr); break; } case OP_TFORCALL: { StkId cb = ra + 3; /* call base */ setobj(cb + 2, ra + 2); setobj(cb + 1, ra + 1); setobj(cb, ra); ks->top = cb + 3; /* func. + 2 args (state and index) */ kp_call(ks, cb, GETARG_C(instr)); base = ci->u.l.base; ks->top = ci->top; instr = *(ci->u.l.savedpc++); /* go to next instruction */ ra = RA(instr); } /*go through */ case OP_TFORLOOP: if (!ttisnil(ra + 1)) { /* continue loop? */ setobj(ra, ra + 1); /* save control variable */ ci->u.l.savedpc += GETARG_sBx(instr); /* jump back */ } break; case OP_SETLIST: { int n = GETARG_B(instr); int c = GETARG_C(instr); int last; ktap_table *h; if (n == 0) n = (int)(ks->top - ra) - 1; if (c == 0) c = GETARG_Ax(*ci->u.l.savedpc++); h = hvalue(ra); last = ((c - 1) * LFIELDS_PER_FLUSH) + n; if (last > h->sizearray) /* needs more space? */ kp_table_resizearray(ks, h, last); for (; n > 0; n--) { ktap_value *val = ra+n; kp_table_setint(ks, h, last--, val); } /* correct top (in case of previous open call) */ ks->top = ci->top; break; } case OP_CLOSURE: { /* need to use closure cache? (multithread contention issue)*/ ktap_proto *p = cl->p->p[GETARG_Bx(instr)]; pushclosure(ks, p, cl->upvals, base, ra); break; } case OP_VARARG: { int b = GETARG_B(instr) - 1; int j; int n = (int)(base - ci->func) - cl->p->numparams - 1; if (b < 0) { /* B == 0? */ b = n; /* get all var. arguments */ checkstack(ks, n); /* previous call may change the stack */ ra = RA(instr); ks->top = ra + n; } for (j = 0; j < b; j++) { if (j < n) { setobj(ra + j, base - n + j); } else setnilvalue(ra + j); } break; } case OP_EXTRAARG: return; case OP_EVENT: { struct ktap_event *e = ks->current_event; if (unlikely(!e)) { kp_error(ks, "invalid event context\n"); return; } setevalue(ra, e); break; } case OP_EVENTNAME: { struct ktap_event *e = ks->current_event; if (unlikely(!e)) { kp_error(ks, "invalid event context\n"); return; } setsvalue(ra, kp_tstring_new(ks, e->call->name)); break; } case OP_EVENTARG: if (unlikely(!ks->current_event)) { kp_error(ks, "invalid event context\n"); return; } kp_event_getarg(ks, ra, GETARG_B(instr)); break; case OP_LOAD_GLOBAL: { ktap_value *cfunc = cfunction_cache_get(ks, GETARG_C(instr)); setobj(ra, cfunc); } break; case OP_EXIT: return; } goto mainloop; }
// returns the other child than the one that would be apropriate for the specified query point Node* otherChild(Vec bfr, const vector<VoronoiCell*>& cells) const { return lessthan(bfr, cells[_m]->particle(), _axis) ? _right : _left; }
bool operator() (int m1, int m2) { if (m1==m2) return false; return lessthan(_cells[m1]->particle(), _cells[m2]->particle(), _axis); }