/** * Test we can add and remove from Q. * * return !0 if an error. */ static int test_add_rmv() { bool error = false; Msg_t stub; Msg_t msg; MpscFifo_t q; Msg_t* pResult; stub.cmd = -1; MpscFifo_t* pQ = initMpscFifo(&q, &stub); pResult = rmv(pQ); TEST(pResult == NULL, "expecting rmv from empty queue to return NULL"); msg.cmd = 1; add(pQ, &msg); TEST(pQ->pHead == &msg, "pHead should point at msg"); TEST(pQ->pTail->pNext == &msg, "pTail->pNext should point at msg"); pResult = rmv(pQ); TEST(pResult != NULL, "expecting Q is not empty"); TEST(pResult != &msg, "expecting return msg to not have original address"); TEST(pResult->cmd == 1, "expecting msg.cmd == 1"); pResult = rmv(pQ); TEST(pResult == NULL, "expecting Q is empty"); pResult = deinitMpscFifo(&q); TEST(pResult == &msg, "expecting last stub to be address of msg"); return error ? 1 : 0; }
/* ************************************************** * from a gvien node, fork two new nodes, * and perform operations such as DCJ, indel, and dup * on the new generated genomes. * **************************************************/ int fork_sim(po o, int pos, double theta, double gamma, double phi){ int i, j, k; //copy for(i=0; i<2; i++){ int pos_n = o->med_genome_idx; printf("processing %dth node\n", pos_n); for(j=0; j<o->v_size; j++) o->v_idx[pos_n][j] = o->v_idx[pos][j]; for(j=0; j<o->e_size[pos]; j++) o->e_idx[pos_n][j] = o->e_idx[pos][j]; //perform mutations mutate(o, pos_n, theta); rmv(o, pos_n, gamma); duplicate(o, pos_n, phi); compute_num_e(o, pos_n); total_score += compute_all_possible_exemplar_orders(o, pos, pos_n, o->v_size/2); //change stats o->valid[pos_n] = VALID3; o->med_genome_idx++; o->num_genome++; } int result =0; for(i=0; i<o->num_genome; i++){ if(o->valid[i] == VALID3) result += o->e_size[i]; } //for(i=0; i<o->num_genome; i++) // printf("%d ", o->valid[i]); //printf("\n"); return result; }
static int comp_(int *l, int r, int i) { while (i < 5) { if (l[i] != 0 && r >= 2) { del(l, i); return (EXIT_SUCCESS); } if (l[i] > 1) { rmv(l, i); return (EXIT_SUCCESS); } if (r == 1) { if (l[i] == 1) { del(l, i); ft_putendl("\n\033[036mYou WIN !\033[0m"); exit(0); } } i++; } return (0); }
static Buf_s *victim (void) { Buf_s *b; int i; for (i = 0; i < Cache.stat.numbufs * 2; i++) { ++Cache.clock; if (Cache.stat.numbufs <= Cache.clock) { Cache.clock = 0; } if (Cache.buf[Cache.clock].clock) { Cache.buf[Cache.clock].clock = FALSE; continue; } b = &Cache.buf[Cache.clock]; if (!b->inuse) { memset(b->d, 0, BLOCK_SIZE); ++b->inuse; ++Cache.stat.gets; if (b->blknum) rmv(b->inode, b->blknum); b->inode = NULL; b->blknum = 0; b->crc = 0; return b; } } fatal("Out of cache buffers"); return NULL; }
static buf_s *victim (void) { buf_s *buf; unint wrap = 0; for (;;) { ++Clock; if (Clock == &Buf[Num_bufs]) { Clock = Buf; if (++wrap > 2) { bdump(); fatal("All buffers in use"); return NULL; } } buf = Clock; if (buf->b_use < 0) { if (buf->b_ant.a_state == ANT_FLUSHING) continue; bflush(buf); aver(buf->b_ant.a_state != ANT_FLUSHING); aver(buf->b_ant.a_state != ANT_DIRTY); buf->b_use = 1; rmv(buf); return buf; } if (buf->b_use == 0) { buf->b_use = -1; } } }
void bchange_blkno (void *data, u64 blkno) { buf_s *buf; buf = addr2buf(data); printf("change %llx -> %llx\n", buf->b_blkno, blkno); rmv(buf); buf->b_blkno = blkno; add(buf); }
void buf_free (Buf_s **bp) { Buf_s *b = *bp; *bp = NULL; aver(b->blknum == ((Node_s *)b->d)->blknum); aver(0 < b->inuse); ++Cache.stat.puts; --b->inuse; if (!b->inuse) { if (b->blknum) rmv(b->inode, b->blknum); } //XXX: Don't know what to do yet with freed block }
void dfa(tnode *head) { int i = 0,k,j=0; strcpy(state[0],head->first); while(1) { for(k=0 ; k<strlen(state[i]) ; k++) if(map[state[i][k] - 48] == 0) { strcat(left[i],follow[state[i][k] - 48]); strcpy(left[i],rmv(left[i])); } else if(map[state[i][k] - 48] == 1) { strcat(right[i],follow[state[i][k] - 48]); strcpy(right[i],rmv(right[i])); } int l=1,r=1; for(k=0 ; k<=i ;k++) { if(!strcmp(state[k],left[i])) l = 0; if(!strcmp(state[k],right[i])) r = 0; } if(l) strcpy(state[++j],left[i]); if(r) strcpy(state[++j],right[i]); if(i == j) break ; i++ ; } printf("\n\n Index State a b "); for(k=0 ; k<=i ;k++) printf("\n%6d %7s %7s %7s ",k+1,state[k],left[k],right[k]); }
void heart_beat() { object *exits, ob, dir; if (!environment(this_object())->is_living()) this_object()->remove(); if (random(100) > 30) return; message("info", "You stumble out of the room in a drunken haze.", ob); say(ob->query_cap_name()+" wanders out of " "the room in a drunken haze.", ob); ob = environment(this_object()); /* if (!(sizeof(environment(ob)->query_destinations()))) { message("info", "You run smack dab right into a wall!", ob); say(ob->query_cap_name()+" runs smack dab right into a wall!", ob); this_object()->remove(); }*/ exits = environment(ob)->query_destinations(); environment(this_object())->move("/wizards/inferno/workroom"); rmv(); return; }
tnode* createTree(char exp[]) { tnode *op,*l,*r; int i=0,j=1,k; while(i<strlen(exp)) { if(isalpha(exp[i]) || exp[i] == '#') { push(nodeInit(exp[i++],j++)); continue ; } op = nodeInit(exp[i++],0); if(op->key == '*') { l = pop(); op->left = l; strcpy(op->first,l->first); strcpy(op->last,l->last); for(k=0;k<strlen(op->first);k++) { strcat(follow[op->first[k] - 48] ,op->last); strcpy(follow[op->first[k] - 48],rmv(follow[op->first[k] - 48])); } } else { r = pop(); l = pop(); op->left = l; op->right = r; if( op->key == '/') { strcpy(op->first,l->first); strcat(op->first,r->first); strcpy(op->last,l->last); strcat(op->last,r->last); if(l->nul == 1 || r->nul == 1) op->nul = 1; else op->nul = 0; } else { strcpy(op->first,l->first); if(l->nul == 1) strcat(op->first,r->first); strcpy(op->last,r->last); if(r->nul == 1) strcat(op->last,l->last); if(l->nul == 1 && r->nul == 1) op->nul = 1; else op->nul = 0; for(k=0;k<strlen(l->last);k++) { strcat(follow[l->last[k] - 48] ,r->first); strcpy(follow[l->last[k] - 48],rmv(follow[l->last[k] - 48])); } } } push(op); } return pop(); }