コード例 #1
0
int main(void) { 
 //   srand(1); 
 //   
 //   //init the data
 //   int i;
 //   for(i = 1; i <= MAX; i++) { 
 //       number[i] = rand() % 100; 
 //   } 
	//heap_size = MAX;
	
	printf("test heapSort\n");
	int a[] = {4,1,3,2,16,9,10,14,8,7};
	heap_size = sizeof(a)/sizeof(a[0]);
	std::copy(a, a+heap_size,number+1);
	
	// print
	printf("before sort:"); 
	printHeap();
	
	// sort
    heapSort(); 
    printf("after sort"); 
	printHeap();

	printf("test priority queue\n");
	heap_size = sizeof(a)/sizeof(a[0]);
	std::copy(a, a+heap_size,number+1);

	buildMaxHeap();
	heapIncreaseKey( 9, 15 );
	printHeap();

    return 0; 
} 
コード例 #2
0
ファイル: test.c プロジェクト: sreejithmm/AlgorithmDS
int main()
{
    int heap[1000]={INT_MIN};
    int k,j,t,l,m,n;
    int size = 0;

    printf("Inserting to the heap\n");
    printf("Enter the number of numbers to be inserted to the heap\n");
    scanf("%d",&n);
    printf("Enter %d numbers to heap\n",n);
    for(j=0;j<n;j++)
    {
        scanf("%d",&k);
        insert(heap,k,&size);

    }
    printf("Print heap\n");
    printHeap(heap,size);
    printf("Minimum value in heap:%d\n",getMin(heap));
    printf("Deleting the minimum value\n");
    deleteMin(heap,&size);
    printf("Minimum value in heap:%d\n",getMin(heap));
    printHeap(heap,size);
    heapSort(heap,size);
    printf("After heap sort\n");
    printHeap(heap,size);
    return 0;



}
コード例 #3
0
ファイル: heap.c プロジェクト: olympian94/programs
int main()
{
	int n, j;
	scanf("%d",&n);
	heap *test_heap=createHeap(n);
	for(j=0; j<n; j++)
		scanf("%d",(test_heap->arr)+j);

	//builds max heap of the array and sets heapsize to len-1
	buildmaxheap(test_heap);
//	heapsort(test_heap);
	/*printf("\n%d",HeapExtractMax(test_heap));
	printf("\n%d",HeapExtractMax(test_heap));
	printf("\n%d",HeapExtractMax(test_heap));
	printf("\n%d",HeapExtractMax(test_heap));*/

	printHeap(test_heap);
	printf("\nIncrease key");
	HeapIncreaseKey(test_heap,4,18);
	printHeap(test_heap);

	printf("\nInsert key");
	MaxHeapInsert(test_heap,20);
	printHeap(test_heap);
	MaxHeapInsert(test_heap,-5);
	printHeap(test_heap);
	MaxHeapInsert(test_heap,10);
	printHeap(test_heap);
	
	printf("\n");
	free(test_heap->arr);	
	free(test_heap);
	return 0;
}
コード例 #4
0
int main() {

    int i;
    int vals[10];
    struct heapStruct *h;
    h = initHeap();

    // Insert from input stream.
    h = readIn(h);
    // print it
    printHeap(h);

    // Delete some and print delete and new heap
    for (i=0; i<9; i++) {
        printf("Delete %d\n",removeMin(h));
        printHeap(h);
    }
    freeHeap(h);

    // Test out array initialization.
    vals[0] = 12, vals[1] = 3, vals[2] = 18, vals[3] = 14, vals[4] = 5;
    vals[5] = 9, vals[6] = 1, vals[7] = 7; vals[8] = 2, vals[9] = 13;

    sort(vals, 10);

    for (i=0; i<10; i++)
        printf("%d ", vals[i]);
    printf("\n");

    system("echo \"done\"");
    return 0;
}
コード例 #5
0
int main()
{
   int max = 0;
   heap[0] = 10;
   heap[1] = 1; heap[2] = 2; heap[3] = 3; heap[4] = 4;
   heap[5] = 7; heap[6] = 8; heap[7] = 9; heap[8] = 10;
   heap[9] = 14; heap[10] = 16;
  
   printf("Original State:\n");
   printHeap(heap);

   buildMaxHeap(heap);
   printf("\n After Heapifying:\n");
   printHeap(heap);

   heapIncreaseKey(heap, 9, 15);
   printf("\n After Increasing S[9]'s key to 15:\n");
   printHeap(heap);

   max = heapExtractMax(heap);
   printf("\n Max key is %d, After Extracting Max Key:\n", max);
   printHeap(heap);

   maxHeapInsert(heap, 13);
   printf("\n After inserting key 13:\n");
   printHeap(heap);

   return 0;
}
コード例 #6
0
ファイル: exp.c プロジェクト: banacorn/Springerpfad
int main () {

    initHeap();

    List * list = nil();
    int i, j;
    for (i = 0; i < 5; i++) {
        List * inner = nil();
        for (j = 0; j < 5; j++)
        {
            Position * p = alloc(sizeof(Position), NULL, NULL);
            inner = cons((void *)p, inner);
        }
        list = cons((void *)inner, list);
    }

    printHeap(HEAP);
    printf("%d\n", heapSize(HEAP));


    release((void *)list);

    printf("========\n");
    printHeap(HEAP);

    return 0;
}
コード例 #7
0
ファイル: Heap.cpp プロジェクト: stepajin/RUN
void Heap::collect() {
    bool print = false;// true;
    
    if (print) {
        cout << endl<< "COLLECT" << endl;
        printHeap();
        if (CallStack::INSTANCE()->getSize() > 0)
            CallStack::INSTANCE()->printStack();
    }
    
    if (print) {
        cout << environments->size() << " environments" << endl;
    }
    
    // Remove released environments (roots)
    vector<Environment *>::iterator e = environments->begin();
    while (e != environments->end()) {
        Environment * env = *e;
    
        if (env->REFERENCES_CNT <= 0) {
            e = environments->erase(e);
            delete env;
        } else {
            ++e;
        }
    }
    
    // Mark
    for (vector<Environment *>::iterator it = environments->begin(); it != environments->end(); ++it) {
        
        Environment * env = *it;

        env->markChildren();
    }
    
    CallStack::INSTANCE()->markChildren();
    
    if (print)
        printHeap();
    
    // Sweep
    vector<VmObject *>::iterator it = heap->begin();

    while(it != heap->end()) {
        VmObject * obj = *it;
        
        if(!obj->isMarked() && !obj->isRetained()) {
            it = heap->erase(it);
            delete obj;
        } else {
            obj->unmark();
            ++it;
        }
    }
    
    if (print)
        printHeap();
}
コード例 #8
0
ファイル: eHeap.c プロジェクト: joorgelm/ufms
int main(){

	eHeap *heap = create(10);

	tElement element = createElement(33);
	add(heap,element);

	element = createElement(32);
	add(heap,element);

	element = createElement(28);
	add(heap,element);

	element = createElement(31);
	add(heap,element);

	element = createElement(29);
	add(heap,element);

	element = createElement(26);
	add(heap,element);

	element = createElement(25);
	add(heap,element);

	element = createElement(30);
	add(heap,element);

	element = createElement(27);
	add(heap,element);

	printHeap(heap);

	exchange(heap,0,6);
	printHeap(heap);

	up_it(heap,6);
	printHeap(heap);

	down_it(heap,2);
	printHeap(heap);

/*	exchange(heap,0,6);
	printHeap(heap);
	printf("\n");
	down(heap,0);
	printHeap(heap);
*/
	return 0;
}
コード例 #9
0
int main() {

    int i;
    int vals[10];
    struct heapStruct *h;
    h = initHeap();

    // Test out individual inserts.
    insertMine(h, 7);
    insertMine(h, 3);
    insertMine(h, 5);
    insertMine(h, 12);
    insertMine(h, 2);
    insertMine(h, 8);
    insertMine(h, 14);
    insertMine(h, 9);
    insertMine(h, 1);
/* 
 
    insert(h, 7);
    insert(h, 3);
    insert(h, 5);
    insert(h, 12);
    insert(h, 2);
    insert(h, 8);
    insert(h, 4);
    insert(h, 9);
    insert(h, 1);
*/
    printHeap(h);

    for (i=0; i<9; i++) {
        printf("Delete %d\n",removeMax(h)); //-----------------------------------------------------------------change here
        printHeap(h);
    }
    freeHeap(h);
    
    // Test out array initialization.
    vals[0] = 12, vals[1] = 3, vals[2] = 18, vals[3] = 14, vals[4] = 5;
    vals[5] = 9, vals[6] = 1, vals[7] = 7; vals[8] = 2, vals[9] = 13;
    
    sort(vals, 10);
    
    for (i=0; i<10; i++)
        printf("%d ", vals[i]);
    printf("\n");
    
 
    return 0;
}
コード例 #10
0
void testHeapify(heap_t* heap){
    puts("\n<BEFORE Heapify>");
    printHeap(heap);
    max_heapify(heap, 1);
    
    puts("<AFTER Heapify>");
    int result = isMaxHeap(heap, 1);
    if(result<0) printf("Wrong input.\n");
    else if(result) printf("Turned into MAX-HEAP\n");
    else printf("NOT MAX-HEAP\n");
    printHeap(heap);
    puts("=================\n");
    
    return;
}
コード例 #11
0
ファイル: k-way.c プロジェクト: marianstefi20/K-Way-Merge
int main() {
    // declarare lista vida
    Element **array;
    int nrListe, j, sumElemente = 0;
	
    printf("Cate liste vrei?");
    scanf("%d", &nrListe);
    array = create_array(nrListe, &sumElemente);
    // Afisare liste
    for(j=0;j<nrListe;j++) {
		printf("\n Lista [%d]\n", j);
		Afisare(array[j]);
	}
    printf("\n");
    
    
    // Definim un nou heap in care vom tine toate elementele
    struct heapStruct *h;
    h = initHeap();
    // Testam adaugarea primelor elemente din fiecare lista
    for(j=0;j<nrListe;j++) 
		insert(h, array[j]->valoare, j);
    printHeap(h);
	
	// Incepem sa punem primul element de pe heap primul
	int *result;
	result = (int*)malloc(sizeof(int)*sumElemente);
	int c = 0;
	printf("Marimea la heap: %d", nrListe);
	printf("Cate elemente vom avea: %d", sumElemente);
	while( nrListe > 0) {         
		heapElement min;
		int i, k;
		min = removeMin(h);
		i = min.list_index;
		k = min.value;
		printf("\n [Valoare|index] = [%d|%d]\n", k, i);
		nrListe--;
		// Trebuie sa stergem nodul cu indexul i
		StergereElement(&array[i]);
		
		
		result[c++] = k;
		if (array[i] != NULL && c < 100)  {
			insert(h, array[i]->valoare, i);         
			nrListe++;
		}
	}
	
	int i;
	printf("\n");
	for(i=0;i<sumElemente;i++) 
		printf("%d  ", result[i]);
	printf("\n");
	
	// In absenta lui free apareau anumite erori interesante
    free(array);

    return 0;
}
コード例 #12
0
ファイル: loadQ.c プロジェクト: odeke-em/utils
void *loadConsume(void *d) {
  void *result = NULL;
  pthread_mutex_lock(&mainHeap_x);
  if (d != NULL) {
    Load *l = (Load *)d;
    unsigned int *t = (unsigned int *)l->data;
    printf("t: %d\n", *t);
    char *msg = malloc(sizeof(char) * (1 + *t));
    int i;
    for (i=0; i < (*t + 1); ++i) {
      msg[i] = 'a' + i;
    }
    msg[i] = '\0';
    result = msg;
    l->id = getAvailableId(l->srcHeap);
    printf("loadId: %d %p\n", l->id, l);
    heapifyFromHead(l->srcHeap);
  #ifdef DEBUG
    printf("\033[96mnew heapify ");
    printHeap(l->srcHeap, printLoad);
  #endif
    pthread_cond_broadcast(&mainHeap_dt);
  }
  pthread_mutex_unlock(&mainHeap_x);
  return result; 
}
コード例 #13
0
int main(int argc, char *argv[]) 
{
	int c=1;
	construct();
	while(c!=0)
	{
		menu();
		scanf("%d",&c);
		if(c==1)
			insert();
		else if(c==2)
			remve();
		else if(c==3)
			peek();
		else if(c==4)
			printHeap();
		else if(c==5)
			printSize();
		else if(c==6)
			printPos();
		else if(c==7)
			c=0;
	}
	return 0;
}
コード例 #14
0
ファイル: cmd_heaptrace.cpp プロジェクト: RdeWilde/hhvm
void CmdHeaptrace::onClient(DebuggerClient &client) {
  if (DebuggerCommand::displayedHelp(client)) return;

  String format;
  String file;
  if (client.argCount() == 3) {
    format = client.argValue(2);
    file = client.argValue(3);
  } else if (client.argCount() != 1) {
    help(client);
    return;
  }

  auto cmd = client.xend<CmdHeaptrace>(this);

  if (file.empty()) {
    cmd->printHeap(client);
  } else {
    std::string formatStr = format->data();
    const auto it = s_formatMap.find(formatStr);

    if (it == s_formatMap.end()) {
      client.print("Unsupported format type");
      return;
    }
    cmd->printGraphToFile(client, file, it->second);
  }

}
コード例 #15
0
int main () {
  // variable declaration
  char command[MAXCMD];
  int* heap = malloc(HEAPSIZE);
  char* argv[MAXARGS];

  // memory management
  *heap = HEAPSIZE;
  bID = 0;

  // Loop - fetch command, call functions
  while(1) {
     printf("> ");
     gets(command);
     parsecommand(command, argv);

     if(strcmp(argv[0], "allocate") == 0)
       Allocate(heap, atoi(argv[1]));
     else if(strcmp(argv[0], "free") == 0)
       Free(heap, atoi(argv[1]));
     else if(strcmp(argv[0], "blocklist") == 0)
       blockList(heap);
     else if(strcmp(argv[0], "writeheap") == 0)
       writeHeap(heap, atoi(argv[1]), argv[2][0], atoi(argv[3]));
     else if(strcmp(argv[0], "printheap") == 0)
       printHeap(heap, atoi(argv[1]), atoi(argv[2]));
     else if(strcmp(argv[0], "quit") == 0)
       break;
  }

  free(heap);
  return 0;
}
コード例 #16
0
ファイル: main.c プロジェクト: teraliv/simulated-heap
void test3() {
    void *p1 = my_malloc(200);
    void *p2 = my_malloc(200);
    void *p3 = my_malloc(200);
    void *p4 = my_malloc(200);
    void *p5 = my_malloc(200);

    my_free(p3);

    my_malloc(210);
    
    my_malloc(150);
    printHeap();
    my_malloc(60);
    my_malloc(50);
    printHeap();
}
コード例 #17
0
ファイル: heap.c プロジェクト: Ikulagin/transmem
static void
removeInt (heap_t* heapPtr)
{
    long* data = heap_remove(heapPtr);
    printf("Removing: %li\n", *data);
    printHeap(heapPtr);
    assert(heap_isValid(heapPtr));
}
コード例 #18
0
ファイル: heap.c プロジェクト: Ikulagin/transmem
static void
insertInt (heap_t* heapPtr, long* data)
{
    printf("Inserting: %li\n", *data);
    assert(heap_insert(heapPtr, (void*)data));
    printHeap(heapPtr);
    assert(heap_isValid(heapPtr));
}
コード例 #19
0
ファイル: heapDriver.c プロジェクト: jwongv/cmps101
int main (int argc, char **argv){

   printf("Welcome to the heap driver program!\n");
   //testing insertion into a heap and testing printheap
   printf("Inserting several nodesand printing the heap\n");
   printf("Result should be 45135, 2534, 325, 50, 211, 25, 3, 294, 1.\n");
   HeapRef heap = newHeap(10);
   insert(heap, 50);
   insert(heap, 211);
   insert(heap, 45135);
   insert(heap, 3);
   insert(heap, 325);
   insert(heap, 2344);
   insert(heap, 25);
   insert(heap, 2534);
   insert(heap, 294);
   insert(heap, 1);
   printHeap(heap);

   //testing maxValue
   printf("\nPrinting max of heap, result should be 45135\n");
   printf("%d\n", maxValue(heap));

   printf("\n");
   //testing deleting the max nodes from a heap
   printf("Deleting 2 max nodes and reheapifying\n");
   printf("Result should be 2344, 325, 211, 294, 50, 1, 25, 3.\n");
   deleteMax(heap);
   deleteMax(heap);
   printHeap(heap);
   printf("\n");

   //testing heap sort function
   printf("Testing heap sort. Result should be 1, 3, 25, 42, 50, 211, 294, 325, 543, 2311, 2344, 2534, 45135.\n\n");
   int keys [] = {50, 211, 45135, 3, 325, 2344, 25, 2534, 294, 1, 42, 543, 2311};
   heapSort(keys, 13);
   for(int i = 0; i < 13; i++){
      printf("%d\n", keys[i]);
   }

   printf("The heap driver is now done!\n");

   return 0;
}
コード例 #20
0
ファイル: test3.c プロジェクト: bigolu/rutgers-spring-2016
int main(int argc, char const *argv[])
{
    void* ptr = malloc(sizeof(double) * 30);
    void *ptr2 = malloc(40);
    free(ptr);
    printHeap();

    free(ptr); //double free

    printHeap();

    int x = 7;
    free(&x); //incorrect free
    free(ptr2);
    printHeap();


    return EXIT_SUCCESS;
}
コード例 #21
0
ファイル: astar.c プロジェクト: wangzun/Algorithm
void astarRun() {

    int map[20][20] =
    {
	{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
	{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
	{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
	{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
	{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
	{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
	{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
	{0,0,3,3,3,3,3,3,0,0,0,0,0,0,0,0,0,0,0,0},
	{0,0,0,0,0,0,0,0,0,3,3,0,0,0,0,0,0,0,0,0},
	{0,0,0,0,0,0,0,0,0,3,3,0,0,0,0,0,0,0,0,0},
	{0,0,0,0,0,0,0,0,0,3,0,0,0,0,0,0,0,0,0,0},
	{0,0,0,0,0,0,0,0,0,3,0,0,0,0,0,0,0,0,0,0},
	{0,0,0,0,0,0,0,0,0,3,0,0,3,0,0,0,0,0,0,0},
	{0,0,0,0,0,0,0,0,0,3,0,0,3,0,0,0,0,0,0,0},
	{0,0,0,0,0,0,0,0,0,3,0,0,3,0,0,0,0,0,0,0},
	{0,0,0,0,0,0,0,0,0,3,0,0,3,0,0,0,0,0,0,0},
	{0,0,0,0,0,0,0,0,0,0,0,0,3,0,0,0,0,0,0,0},
	{0,0,0,0,0,0,0,0,0,0,0,0,3,0,0,0,0,0,0,0},
	{0,0,0,0,0,0,0,0,0,0,0,0,3,0,0,0,0,0,0,0},
	{0,0,0,0,0,0,0,0,0,0,0,0,3,0,0,0,0,0,0,0},
    };
    int in_open[20][20] ={0};

    Star begin_star ={0,0,0,0,0};
    Star end_star = {19,19,0,0,0};

    Heap *open_heap;
    Star star[300];
    createHeap(open_heap,star,0,min_heap_compare);
    find_path(begin_star,end_star,map,open_heap,in_open);
    printHeap(open_heap);

    for (int i=0;i<20;i++) {
	for(int j=0;j<20;j++) {
	    if (map[i][j]==0){
		putchar('-');
		putchar(' ');
	    }
	    else if(map[i][j] ==1){
		putchar('o');
		putchar(' ');
	    }else
	    {
		putchar('#');
		putchar(' ');
	    }
	}
	putchar('\n');
    }
}
コード例 #22
0
ファイル: maxHeapify.cpp プロジェクト: ozt88/NEXT_14_THIRD
//MaxHeapify된 Heap을 출력하고 MaxHeap이 맞는지 출력하는 함수
void test_heapify()
{
	heap_t* testHeap = makeSampleMaxHeap();
	printHeap( testHeap );
	char* strIsMaxHeap = isMaxHeap( testHeap ) ? "This is Max Heap." : "This is not Max Heap.";
	printf( "%s\n" , strIsMaxHeap );

	if( testHeap != nullptr )
	{
		delete testHeap;
		testHeap = nullptr;
	}
}
コード例 #23
0
void heapSort() { 
    buildMaxHeap();
	printf("\ncreate heap:"); 
	printHeap();
	
	int heap_size_ = heap_size;
	for(int i=heap_size; i>=2; i--)
	{
		std::swap(number[1], number[i]);
		heap_size--;
		maxHeapify(1);
	}
	heap_size = heap_size_;
} 
コード例 #24
0
ファイル: testgc.c プロジェクト: lborwell/gc
void runTest(Test* t){
	//print results
    puts("\nStarting heap:");
    puts("=========================================");
    printHeap(t->h);
    puts("\nStarting stack:");
    puts("=========================================");
    printStack(t->s);
    
    collect(t->s,&(t->h),0);

    puts("\nCollected heap:");
    puts("=========================================");
    printHeap(t->h);

    puts("\nCollected stack:");
    puts("=========================================");
    printStack(t->s);

    puts("\nBigdata heap:");
    puts("====================================");
    printHeap(bigdataheap);
}
コード例 #25
0
int printJustHuffCode( int index )
{
    if( GlobalHuffCodes.ptCharFreq[index].ptParent == 0 )
    {
        fprintf(stderr,"\nError: can not translate '%c' index %d\n", GlobalHuffCodes.ptCharFreq[index].cCharacter, index );
        fprintf(stderr,"\n       parent: %d freq: %d ", GlobalHuffCodes.ptCharFreq[index].ptParent, GlobalHuffCodes.ptCharFreq[index].nFreq );
        printHuffTree();
        printHeap( GlobalHuffCodes.pptCharFreqHeap );
        return 1;
    }
    else
        printHuffCodeRecursion( &GlobalHuffCodes.ptCharFreq[index], 0 );
    return 0;
}
コード例 #26
0
ファイル: binheap.c プロジェクト: ruitaoH/task
int main(){
    srand((unsigned)time(NULL));
    PriorityQueue H = Initialize(15);
    int choice;
    int item;
    int i;

    instructions();
    printf("your choice:");
    scanf("%d",&choice);

    while(choice != 3){
        switch(choice){
            case 1:
                for(i = 0;i < H->Capacity;i++){
                    Insert(rand()%101,H);
                }
                printf("%d\n",H->Capacity);
                printf("%d\n",H->Size);
                printHeap(H);
                break;
            case 2:
                DeleteMin(H);
                printHeap(H);
                break;
            default:
                printf("\nInvalid choice\n");
                instructions();
        }
        printf("\nyour choice:");
        scanf("%d",&choice);
    }
    Destroy(H);
    printf("\nrun to end\n");

    return 0;
}
コード例 #27
0
ファイル: main.c プロジェクト: tapanavasthi/dsa
/* Driver program to test above functions*/
int main()
{

printf("Hello World\n");

int *try;
try=(int *)malloc(sizeof(int)*10);
try[0]=4;
try[1]=1;
try[2]=3;
try[3]=2;
try[4]=16;
try[5]=9;
try[6]=10;
try[7]=14;
try[8]=8;
try[9]=7;



struct heap* H1;

H1=initHeap(H1,try,10,10);
 
//heapify(H1,2);
printHeap(H1);
H1=buildMinHeap(H1);
printHeap(H1);
heapSort(H1);
//int max=heapExtractMax(H1);
//printf("\nmax:%d\n",max);
printHeap(H1);

H1=minHeapInsert(H1,5);
printHeap(H1);
 return 0;
}
コード例 #28
0
ファイル: main.c プロジェクト: teraliv/simulated-heap
void test2() {
    void *p1 = my_malloc(200);
    void *p2 = my_malloc(50);
    void *p3 = my_malloc(200);
    void *p4 = my_malloc(350);
    void *p5 = my_malloc(200);

    
    my_free(p2);
    my_free(p4);
    
    void *p6 = my_malloc(50);
    void *p7 = my_malloc(200);
    void *p8 = my_malloc(100);

    printHeap();
}
コード例 #29
0
void LLScriptLSOParse::printData(LLFILE *fp)
{
	


	printNameDesc(fp);

	printRegisters(fp);

	printGlobals(fp);

	printGlobalFunctions(fp);

	printStates(fp);

	printHeap(fp);
}
コード例 #30
0
/**
   Called by: addToHeap (Timer*)
*/
Result TimerMinHeap::upHeapify (Timer* pTimer)
{
  // Insert into minheap, minheapify
  // At index i; children at (2i+1) and (2i+2)
  // If minheap property is satisfied, then we are done!
  UINT32 heaped = 0;
  Timer** minheap = getHeap ();
  UINT32 index = getNumberOfTimers ();
  minheap [index] = pTimer;

  if (index == 0) // The first timer
    {
    }
  else
    {
      while (!heaped)
	{
	  UINT32 parent = floor((index - 1)/2);
	  UINT64 parentFiringTime = minheap [parent]->getWhenToFire ();
	  UINT64 indexFiringTime = minheap [index]->getWhenToFire ();
	  if (uint64LT (parentFiringTime, indexFiringTime))
	    {
	      heaped = 1;
	    }
	  else
	    {
	      Timer* tmp = minheap [index];
	      minheap [index] = minheap [parent];
	      minheap [parent] = tmp;
	      
	      index = parent;
	    }

	  if (parent == 0)
	    heaped = 1;	  
	}
    }
  incNumberOfTimers ();
  //COUT << "TimerMinHeap::upHeapify (): Current number of timers = " << getNumberOfTimers () << endl;
  COUT << "Added timer " << hex << pTimer 
       << " to timer minheap [" << this << dec << "]" << " (number of timers in heap = "
       << getNumberOfTimers () << ")." << endl;
  printHeap ();
  return OK;
}