int initializeSet(int lines, Cache test, int assoc, char *kind){ test->valid=0; test->miss=0; test->cold_misses=0; test->capacity_miss=0; test->conflict_miss=0; test->memory_access=0; test->hits=0; test->total_misses=0; int count=0; test->blocks=(CacheArray**)malloc(lines * sizeof(struct cache_array)); for (int i=0;i<lines;i++){ test->blocks[i]=(CacheArray*)malloc(assoc *sizeof(struct cache_array)); if((strlen(test->type)>=7)&&(strncmp(test->type,"assoc:", 5)==0)){ /*create a lru policy using dll for each individual set*/ if(strcmp(kind,"lru")==0){ test->blocks[i]->LRU=SLCreate(); test->blocks[i]->FIFO=NULL; // printf("LRU DLL created\n"); } /*create a queue for each individual set*/ if(strcmp(kind,"fifo")==0){ test->blocks[i]->FIFO=queueCreate(assoc); test->blocks[i]->LRU=NULL; // printf("LRU DLL created\n"); } } for(int j=0;j<assoc;j++){ test->blocks[i][j].valid=0; test->blocks[i][j].tag=-1; test->blocks[i][j].indexSet=-1; test->blocks[i][j].offSet=-1; count++; // printf("%d, Valid %d Tag %lld\n", j, test->blocks[i][j].valid, test->blocks[i][j].tag); } count++; } if((strcmp(test->type,"FA")==0)||((strlen(test->type)==5)&& (strcmp(test->type,"assoc")==0))){ /*only for FA. Either lru policy or fifo*/ if(strcmp(kind,"lru")==0){ test->LRU=SLCreate(); test->FIFO=NULL; } if(strcmp(kind,"fifo")==0){ test->FIFO=queueCreate(lines); test->LRU=NULL; } } return 0; }
int main(int argc, char *argv[]) { Queue *q = queueCreate(); queuePush(q, 'a'); queuePush(q, 'b'); queuePush(q, 'c'); queuePush(q, 'd'); printf("%c", queuePop(q)); printf("%c", queuePop(q)); printf("%c", queuePop(q)); queuePush(q, 'e'); queuePush(q, '\n'); printf("%c", queuePop(q)); printf("%c", queuePop(q)); printf("%c", queuePop(q)); queuePush(q, 0); queuePush(q, 0); queuePush(q, 0); queuePush(q, 0); queueDelete(q); return 0; }
struct sem* createNewSem(unsigned int hash_id, char *name, unsigned value){ struct sem *new_sem; new_sem = malloc(sizeof(struct sem)); new_sem->hash.id = hash_id; new_sem->hash.next = NULL; new_sem->hash.name = name; new_sem->value = value; pthread_mutex_init(&new_sem->lock, NULL); new_sem->queue = queueCreate(MAX_NODE_NUM+1, sizeof(struct req_node_info)); return new_sem; }
int main(){ QUEUE Queue = queueCreate(5); int i=0,data=2; for(i=1;i<4;i++){ if(enqueue(Queue,i)) printf("enqueue :%i\n",i); //printf("fghfhf %i\n",Queue->s1->index ); } STACK stack3=queueToStack(Queue); dequeue(Queue,&data); printf("dequeue :%i\n",data);//3 //printf("thrth %i\n",Queue->s1->index ); queuePeek(Queue,&data); printf("Peek :%i\n",data);//4 queuePeek(Queue,&data); printf("Peek :%i\n",data);//4 queuePeek(Queue,&data); printf("Peek :%i\n",data);//4 dequeue(Queue,&data); printf("dequeue :%i\n",data);//3 for(i=5;i<11;i++){ if(enqueue(Queue,i)) printf("enqueue :%i\n",i); } queuePeek(Queue,&data); printf("Peek :%i\n",data); for(i=5;i<11;i++){ if(dequeue(Queue,&data)) printf("dequeue :%i\n",data); } queueDestroy(Queue); while(stackPop(stack3,&data)){ printf("queue to stack elements :%i\n",data); } }
int main() { Queue q; queueCreate(&q, 100); for (int i = 0; i < 10; ++i) { queuePush(&q, i); } printf("Bingo\n"); for (int i = 0; i < 10; ++i) { queuePop(&q); } return 0; }
int main() { Queue *queue = malloc(sizeof(Queue)); queueCreate(queue, 10); queuePush(queue, 1); queuePush(queue, 2); queuePush(queue, 3); queuePop(queue); queuePop(queue); assert(queuePeek(queue) == 3); assert(queueEmpty(queue) == 0); queueDestroy(queue); return 0; }
void rbtreeToDot(RBTree tree, const char* racine, const char* dossier) { assert(!rbtreeEmpty(tree)); static int numerofichier=0; char final[30]; sprintf(final,"%s/%s%d.dot",dossier,racine,numerofichier++); FILE*fd = fopen(final,"wt"); fprintf(fd,"digraph G { \n"); Node node; QUEUE queue; queueCreate(&queue); queueAdd(queue,rbfirst(tree)); do { node = queueRemove(queue); if(node->color==red) fprintf(fd,"\t%d [color=red];\n",keyPut(node->key)); else fprintf(fd,"\t%d [color=black];\n",keyPut(node->key)); if(node->left != tree->nil) { fprintf(fd,"\t%d -> %d;\n",keyPut(node->key),keyPut(node->left->key)); if(node->left->color==red) fprintf(fd,"\t%d [color=red];\n",keyPut(node->left->key)); else fprintf(fd,"\t%d [color=black];\n",keyPut(node->left->key)); } if(node->right != tree->nil) { fprintf(fd,"\t%d -> %d;\n",keyPut(node->key),keyPut(node->right->key)); if(node->right->color==red) fprintf(fd,"\t%d [color=red];\n",keyPut(node->right->key)); else fprintf(fd,"\t%d [color=black];\n",keyPut(node->right->key)); } if(node->left != tree->nil) queueAdd(queue,node->left); if(node->right != tree->nil) queueAdd(queue,node->right); } while(!queueEmpty(queue)); fprintf(fd,"}\n"); fclose(fd); }
ServiceConnection serviceConnectionCreate(void) { ServiceConnection sc; sc = (ServiceConnection) malloc(sizeof(ServiceConnectionStruct)); if(sc) { sc->requestedUpdateRateHz = 0; sc->confirmedUpdateRateHz = 0; sc->lastSentTime = 0; sc->timeoutSec = 0; sc->nextRequestTimeSec = 0; sc->presenceVector = 0; sc->commandCode = 0; sc->sequenceNumber = 0; sc->instanceId = -1; sc->isActive = JAUS_FALSE; sc->queueSize = 0; sc->nextSc = NULL; sc->address = jausAddressCreate(); if(!sc->address) { // Failed to init address free(sc); return NULL; } sc->queue = queueCreate(); if(!sc->queue) { // Failed to init queue jausAddressDestroy(sc->address); free(sc); return NULL; } return sc; } else { return NULL; } }
ServiceConnection serviceConnectionCreate(void) { ServiceConnection sc; sc = (ServiceConnection) malloc(sizeof(ServiceConnectionStruct)); if(sc) { sc->address = jausAddressCreate(); sc->queryMessage = NULL; sc->queue = queueCreate(); sc->serviceConnectionType = 0; return sc; } else { return NULL; } }
struct Queue* tokenize(const char* const cmdLine) { struct Queue* tokens=queueCreate(); struct StringBuffer* sb=strBufCreate(); char* s; int i; bool inQuotes=false, delimiter; for (i=0; i<strlen(cmdLine); i++) { delimiter=false; if(cmdLine[i]=='\"' || cmdLine[i]=='\'') { inQuotes=!inQuotes; } else if (!inQuotes) { delimiter=checkDelimiter(&i, cmdLine, sb, tokens); if (!delimiter) { //Non-Delimiter Character strBufAppendChar(sb, cmdLine[i]); } } //End !inQuotes Check else { //inQuotes strBufAppendChar(sb, cmdLine[i]); } } if (strBufLength(sb)>0) { s=strBufToString(sb); strBufClear(sb); queueInsert(tokens, s); } strBufDestroy(sb); return tokens; }
int main(void){ int i=0; queueCreate (12); //create queue for(;i<13;i++){ if(!queueIsFull ()) //check whether queue is full or not if not data enter otherwise discard enqueue(15+i); //enter data to queue } //queueDestroy (); //destroy the queue for(i=0;i<12;i++) printf("%d..asasadasj\n",StArray[i]); //print the data in the queue from the begining to show it has implemented correctly //printf("%d..\n",dequeue()); //dequeue the que and print //printf("%d..\n",queuePeek ());//peek the que and print return 0; }
int main() { Queue queue; queueCreate(&queue, 5); queuePush(&queue, 1); queuePush(&queue, 2); queuePop(&queue); printf("%d\n", queuePeek(&queue)); queuePop(&queue); queuePush(&queue, 1); queuePush(&queue, 2); printf("%d\n", queuePeek(&queue)); queuePush(&queue, 3); printf("%d\n", queuePeek(&queue)); printf("%d\n", queuePeek(&queue)); queueDestroy(&queue); return 0; }
int TestQueue() { Queue* Q; int i; Q = malloc(sizeof(struct Queue)); queueCreate(Q, 10); for (i = 0; i < 100; ++i) queuePush(Q, i); while (!queueEmpty(Q)) { printf("%d ", queuePeek(Q)); queuePop(Q); } printf("\n"); queueDestroy(Q); }
void rbtreeMapDebug(RBTree tree) { assert(!rbtreeEmpty(tree)); Node node; QUEUE queue; queueCreate(&queue); queueAdd(queue,rbfirst(tree)); printf("\033[01;35m==== Début de l'arbre ====\n\033[0m"); do { node = queueRemove(queue); if(rbExists(node->left) || rbExists(node->right) || rbfirst(tree)==node) { if(node->father != tree->root) printf("(pere: %d)",keyPut(node->father->key)); if(node->color==red) printf("\033[01;31m"); if(rbfirst(tree)==node) printf("\033[01;32m"); printf("Noeud %d\033[0m",keyPut(node->key)); if(rbExists(node->left)) { if(node->left->color==red) printf("\033[01;31m"); printf(", "); if(node->left->father != tree->root) printf("(pere: %d) ",keyPut(node->left->father->key)); printf("%d fils gauche\033[0m",keyPut(node->left->key)); } if(rbExists(node->right)) { printf(", "); if(node->right->color==red) printf("\033[01;31m"); if(node->right->father != tree->root) printf("(pere: %d) ",keyPut(node->right->father->key)); printf("%d fils droit\033[0m",keyPut(node->right->key)); } printf("\n"); } if(node->left != tree->nil) queueAdd(queue,node->left); if(node->right != tree->nil) queueAdd(queue,node->right); } while(!queueEmpty(queue)); printf("\n"); }
int main (int argc, char **argv) { int i; int val[] = {2,3,6,8,10,12,14,16,18,20,21,22,23,24,25}; int value; Queue q ; queueCreate(&q, 1024); for(i = 0; i < 15; i++) { queuePush(&q, val[i]); print_list(q.node); } for(i = 0; i < 15; i++) { value = queuePeek(&q); printf("val = %d\n", value); queuePop(&q); print_list(q.node); } queueDestroy(&q); return 0; }
void stackCreate(struct node **top){ queueCreate(top); //create stack using queue }
int main(void) { queueHead* queue; int i1 = 1; int i2 = 2; int i3 = 3; int i4 = 4; /* * Test 1 */ /* Create queue */ assert(NULL != (queue = queueCreate())); /* Fill the queue */ assert(1 == (queueAdd(queue, &i1))); /* Insert 1 */ assert(1 == (queueAdd(queue, &i2))); /* Insert 2 */ assert(1 == (queueAdd(queue, &i3))); /* Insert 3 */ assert(1 == (queueAdd(queue, &i4))); /* Insert 4 */ /* Check the queue */ assert(1 == (*(int*)queueFirst(queue))); /* Check 1 */ assert(1 == (*(int*)queueRemove(queue))); /* Remove 1 */ assert(2 == (*(int*)queueFirst(queue))); /* Check 2 */ assert(2 == (*(int*)queueRemove(queue))); /* Remove 2 */ assert(3 == (*(int*)queueFirst(queue))); /* Check 3 */ assert(3 == (*(int*)queueRemove(queue))); /* Remove 3 */ assert(4 == (*(int*)queueFirst(queue))); /* Check 4 */ assert(4 == (*(int*)queueRemove(queue))); /* Remove 4 */ assert(NULL == (queueFirst(queue))); /* Check empty */ assert(NULL == (queueRemove(queue))); /* Queue is empty */ /* Clear the queue */ queueFree(queue); printf("Queue: Test1 success!\n"); /* * Test 2 */ /* Create queue */ assert(NULL != (queue = queueCreate())); /* Fill the queue */ assert(1 == (queueAdd(queue, &i1))); /* Insert 1 */ assert(1 == (*(int*)queueRemove(queue))); /* Remove 1 */ assert(1 == (queueAdd(queue, &i1))); /* Insert 1 */ assert(1 == (queueAdd(queue, &i2))); /* Insert 2 */ assert(1 == (*(int*)queueRemove(queue))); /* Remove 1 */ assert(2 == (*(int*)queueRemove(queue))); /* Remove 2 */ assert(1 == (queueAdd(queue, &i1))); /* Insert 1 */ assert(1 == (*(int*)queueFirst(queue))); /* Check 1 */ assert(1 == (queueAdd(queue, &i2))); /* Insert 2 */ assert(1 == (*(int*)queueRemove(queue))); /* Remove 1 */ assert(1 == (queueAdd(queue, &i3))); /* Insert 3 */ assert(2 == (*(int*)queueRemove(queue))); /* Remove 2 */ assert(1 == (queueAdd(queue, &i4))); /* Insert 4 */ assert(3 == (*(int*)queueRemove(queue))); /* Remove 3 */ assert(4 == (*(int*)queueRemove(queue))); /* Remove 4 */ /* Fill the queue */ assert(1 == (queueAdd(queue, &i1))); /* Insert 1 */ assert(1 == (queueAdd(queue, &i2))); /* Insert 2 */ assert(1 == (queueAdd(queue, &i3))); /* Insert 3 */ assert(1 == (queueAdd(queue, &i4))); /* Insert 4 */ /* Check the queue */ assert(1 == (*(int*)queueRemove(queue))); /* Remove 1 */ assert(2 == (*(int*)queueFirst(queue))); /* Check 2 */ assert(2 == (*(int*)queueRemove(queue))); /* Remove 2 */ assert(3 == (*(int*)queueRemove(queue))); /* Remove 3 */ assert(4 == (*(int*)queueRemove(queue))); /* Remove 4 */ assert(NULL == (queueFirst(queue))); /* Check empty */ assert(NULL == (queueRemove(queue))); /* Queue is empty */ /* Clear the queue */ queueFree(queue); printf("Queue: Test2 success!\n"); return 0; }