Queue CqsCreate(void) { Queue q = (Queue)CmiAlloc(sizeof(struct Queue_struct)); q->length = 0; q->maxlen = 0; #ifdef FASTQ /* printf("\nIN fastq"); */ #endif CqsDeqInit(&(q->zeroprio)); CqsPrioqInit(&(q->negprioq)); CqsPrioqInit(&(q->posprioq)); return q; }
Queue CqsCreate(void) { Queue q = (Queue)CmiAlloc(sizeof(struct Queue_struct)); q->length = 0; q->maxlen = 0; #ifdef FASTQ /* printf("\nIN fastq"); */ #endif CqsDeqInit(&(q->zeroprio)); CqsPrioqInit(&(q->negprioq)); CqsPrioqInit(&(q->posprioq)); #if CMK_USE_STL_MSGQ q->stlQ = (void*) new conv::msgQ<prio_t>; #endif return q; }
/** Find or create a bucket in the hash table for the specified priority. */ _deq CqsPrioqGetDeq(_prioq pq, unsigned int priobits, unsigned int *priodata) { unsigned int prioints = (priobits+CINTBITS-1)/CINTBITS; unsigned int hashval, i; int heappos; _prioqelt *heap, pe, next, parent; _prio pri; int mem_cmp_res; unsigned int pri_bits_cmp; static int cnt_nilesh=0; #ifdef FASTQ /* printf("Hi I'm here %d\n",cnt_nilesh++); */ #endif /* Scan for priority in hash-table, and return it if present */ hashval = priobits; for (i=0; i<prioints; i++) hashval ^= priodata[i]; hashval = (hashval&0x7FFFFFFF)%PRIOQ_TABSIZE; #ifndef FASTQ for (pe=pq->hashtab[hashval]; pe; pe=pe->ht_next) if (priobits == pe->pri.bits) if (memcmp(priodata, pe->pri.data, sizeof(int)*prioints)==0) return &(pe->data); #else parent=NULL; for(pe=pq->hashtab[hashval]; pe; ) { parent=pe; pri_bits_cmp=pe->pri.bits; mem_cmp_res=memcmp(priodata,pe->pri.data,sizeof(int)*prioints); if(priobits == pri_bits_cmp && mem_cmp_res==0) return &(pe->data); else if(priobits > pri_bits_cmp || (priobits == pri_bits_cmp && mem_cmp_res>0)) { pe=pe->ht_right; } else { pe=pe->ht_left; } } #endif /* If not present, allocate a bucket for specified priority */ pe = (_prioqelt)CmiAlloc(sizeof(struct prioqelt_struct)+((prioints-1)*sizeof(int))); pe->pri.bits = priobits; pe->pri.ints = prioints; memcpy(pe->pri.data, priodata, (prioints*sizeof(int))); CqsDeqInit(&(pe->data)); pri=&(pe->pri); /* Insert bucket into hash-table */ next = pq->hashtab[hashval]; #ifndef FASTQ pe->ht_next = next; pe->ht_handle = (pq->hashtab+hashval); if (next) next->ht_handle = &(pe->ht_next); pq->hashtab[hashval] = pe; #else pe->ht_parent = parent; pe->ht_left = NULL; pe->ht_right = NULL; if(priobits > pri_bits_cmp || (priobits == pri_bits_cmp && mem_cmp_res>0)) { if(parent) { parent->ht_right = pe; pe->ht_handle = &(parent->ht_right); } else { pe->ht_handle = (pq->hashtab+hashval); pq->hashtab[hashval] = pe; } /* pe->ht_handle = &(pe); */ } else { if(parent) { parent->ht_left = pe; pe->ht_handle = &(parent->ht_left); } else { pe->ht_handle = (pq->hashtab+hashval); pq->hashtab[hashval] = pe; } /* pe->ht_handle = &(pe); */ } if(!next) pq->hashtab[hashval] = pe; #endif pq->hash_entry_size++; #ifndef FASTQ if(pq->hash_entry_size > 2*pq->hash_key_size) CqsPrioqRehash(pq); #endif /* Insert bucket into heap */ heappos = pq->heapnext++; if (heappos == pq->heapsize) CqsPrioqExpand(pq); heap = pq->heap; while (heappos > 1) { int parentpos = (heappos >> 1); _prioqelt parent = heap[parentpos]; if (CqsPrioGT(pri, &(parent->pri))) break; heap[heappos] = parent; heappos=parentpos; } heap[heappos] = pe; #ifdef FASTQ /* printf("Hi I'm here222\n"); */ #endif return &(pe->data); }