int checkPQEnqueueing (Event *list, int listLength, int result)
{
    PriorityQueue *queue = createPriorityQueue();
    int notFound = 0;
    Event *current = NULL;
    Event *current2 = NULL;
    
    queue = insertDataToPriorityQueue(queue, list, 0);
    
    for (current = dequeuePriorityQueue(queue); current != NULL; current = dequeuePriorityQueue(queue))
    {
        for (notFound = 1, current2 = list; current2 != NULL; moveToNextEvent(&current2))
        {
            if (current == current2)
            {
                notFound = 0;
                break;
            }
        }
        if (notFound)
        {
            result--;
        }
    }
    
    freePriorityQueue(&queue);
    
    return result;
}
Beispiel #2
0
TPriorityQueue *createMaximumPriorityQueue(unsigned int size){

	TPriorityQueue *pq = createPriorityQueue(size);
	TDataPriorityQueue *data = pq->data;

	data->compareIns = compareMaximumPriorityQueue;
	data->compareOrd = compareMinimumPriorityQueue;

	return pq;
}
PriorityQueue* insertDataToPriorityQueue (PriorityQueue *queue, Event *list, int startingPriority)
{
    if (list == NULL)
    {
        return queue;
    }
    else if (queue == NULL)
    {
        return insertDataToPriorityQueue(createPriorityQueue(), list, startingPriority);
    }
    
    queue = enqueuePriorityQueue(queue, NULL, list, startingPriority);
    
    return insertDataToPriorityQueue(queue, peekNextEvent(list), startingPriority+1);
}
int testPQ() {
    printf("\nTestPQ started\n");
    PCB pcb = {new, 1, 23, 0, 2, 23, 23, 4, 5}; 
    //toString(&pcb);   
    fifo_queue *thePQ = createPriorityQueue();
    printf("Testing priority queue toString on empty\n");
    PriorityQueuetoString(thePQ);
    printf("Testing priority queue addPCB\n");   
    addPCB(&pcb, thePQ);
    printf("Testing priority queue toString\n");
    PriorityQueuetoString(thePQ);
    printf("Testing that I didn't mess up any queues with the last toString\n");
    PriorityQueuetoString(thePQ);
    printf("Testing GetNext \n");
    toString(GetNext(thePQ));
    printf("Testing GetNext on Empty PQ\n");
    toString(GetNext(thePQ));
    return (EXIT_SUCCESS);
}
Beispiel #5
0
void testPriorityQueue() {
  PriorityQueuePointer pq = createPriorityQueue( 12 );
  printf( "Is newly created income empty? %d\n\n", 
    isPriorityQueueEmpty(pq) );


  pqEnqueue( pq, createProcess(2,3) );
  pqEnqueue( pq, createProcess(2,3) );
  pqEnqueue( pq, createProcess(2,3) );
  pqEnqueue( pq, createProcess(2,3) );
  pqEnqueue( pq, createProcess(2,3) );

  printPriorityQueue( pq );

  printf( "\n" );

  while( !isPriorityQueueEmpty(pq) ) {
    ProcessPointer pp = pqDequeue( pq );
    printf( "highest priority item = %8.4f\n", pp->serviceTime );
  } // while

} // testPriorityQueue()
Beispiel #6
0
void compress()
{
	Hashtable *ht = createHashtable();
	linkedList *charBits = newLinkedList();
    FILE *file = fopen("file.txt", "r");
    FILE *backp = fopen("backp.txt","w");
    FILE *backp2 = fopen("backp2.txt","w");
    PriorityQueue * queue = createPriorityQueue();
    int characters[256],i,count=0,j,count2=0;
    unsigned char currentChar;
    memset(characters,0,sizeof(characters));

    if (file == NULL)
    {
        printf ("ERROR 404: FILE NOT FOUND\n");
        exit(0);
    }
    else
    {
        do
        {
            currentChar = fgetc(file);
            if(currentChar == UNSIGNED_EOF)
            {
                break;
            }
            characters[currentChar]++;
            count2++;
        }
        while(currentChar != UNSIGNED_EOF);
    }
    for(i=0; i < UNSIGNED_EOF; i++)
    {
        if(characters[i]!=0)
        {
            count++;
            enqueue(queue,i,characters[i],NULL);
        }
    }
    for(j = count ; j>1 ; j--)
    {
        dequeue(queue);
    }
	generateBits(ht, charBits, returnBT(queue));
	freeBT(returnBT(queue));
	rewind(file);
	do
    {
        currentChar = fgetc(file);
        if(currentChar == UNSIGNED_EOF)
        {
            break;
        }
        fprintf(backp,"%s",get(ht,currentChar));
    }
    while(currentChar != UNSIGNED_EOF);

    fprintf(backp2,"%d\n",count); // SALVA QUANTAS LINHAS DE HASH TERÁ NO ARQUIVO

    for(i=0; i < UNSIGNED_EOF; i++)
    {
        if(characters[i]!=0)
        {
            fprintf(backp2,"%c %s\n",i,get(ht,i)); //SALVA QUAL CARACTERE E O SEU CODIGO ASCII REDUZIDO NA HASH
        }
    }
    fprintf(backp2,"%d\n",count2); // SALVA A QUANTIDADE DE CHARS QUE EXISTIRÃO
    fclose(backp);
    writeCompressedData(backp2);
	fclose(backp2);
    fclose(file);
    rename("backp2.txt","compressed.txt");
    remove("backp.txt");
}