#include "oldheap.h"
#include "host.h"
#include "cutil.h"
#include "freelist.h"
#include "danerror.h"
#include "emalloc.h"
#include <stdio.h>
Defines | |
#define | FATHER(N) ((N)>>1) |
#define | LEFTSON(N) ((N)<<1) |
#define | RIGHTSON(N) ((N)<<1 + 1) |
Functions | |
HEAP * | MakeHeap (int Size) |
int | HeapPop (HEAP *Heap, FLOAT32 *Key, void *out_ptr) |
int | HeapPopWorst (HEAP *Heap, FLOAT32 *Key, void *out_ptr) |
bool | HeapPushCheckSize (HEAP *Heap, FLOAT32 Key, void *Data) |
void | HeapPush (HEAP *Heap, FLOAT32 Key, void *Data) |
void | HeapStore (HEAP *Heap, HEAPENTRY *Entry) |
int | GetTopOfHeap (HEAP *Heap, HEAPENTRY *Entry) |
void | FreeHeapData (HEAP *Heap, void_dest destructor) |
#define FATHER | ( | N | ) | ((N)>>1) |
#define LEFTSON | ( | N | ) | ((N)<<1) |
#define RIGHTSON | ( | N | ) | ((N)<<1 + 1) |
This routine is similar to FreeHeap in that it deallocates the memory consumed by the heap. However, it also calls Deallocator for each item in the heap so that this data is also deallocated.
Heap | heap whose data is to be freed | |
Deallocator | function to be used to deallocate data |
Globals:
This routine removes the top item on the heap and copies its contents into Entry.
Heap | ptr to heap whose top is to be removed and returned | |
Entry | ptr to heap entry to be filled with top entry on Heap |
Globals:
This routine removes the top item on the heap and places its contents into Key and Data.
Globals:
Heap | ptr to heap whose top is to be removed and returned | |
Key | place to put key of top heap item | |
Data | place to put data of top heap item |
HeapPopWorst
Remove the largest item from the heap.
Heap | ptr to heap whose top is to be removed and returned | |
Key | place to put key of top heap item | |
Data | place to put data of top heap item |
This routine stores Data into Heap and associates it with Key. The heap is maintained in such a way that the item with the lowest key is always at the top of the heap.
Globals:
Heap | ptr to heap to store new item in | |
Key | numeric key associated with new item | |
Data | ptr to data contents of new item |
This routine stores Entry into Heap. The heap is maintained in such a way that the item with the lowest key is always at the top of the heap.
Globals:
Heap | ptr to heap to store new item in | |
Entry | ptr to item to be stored in Heap |
HEAP* MakeHeap | ( | int | Size | ) |
This routine creates and initializes a new heap data structure containing Size elements. In actuality, Size + 1 elements are allocated. The first element, element 0, is unused, this makes the index arithmetic easier.
Globals:
Size | maximum number of entries in the heap |