| #define HEAP_ORDER_CRESCENT
1 #define HEAP_ORDER_DECRESCENT -1 typedef struct _Heap { int size; destroyfunc* destroy; comparefunc* cmp; void** tree; int order; }Heap; The Heap data structure represents a heap, a special kind of tree. |
| Heap* heap_create(destroyfunc*
destroy, comparefunc* cmp, int order) description: creates a new, empty heap. The destroy parameter is a pointer to a user-defined destroyfunc. This function'll be used by heap_destroy to free dynamically allocated data. If the data to be inserted in the heap should not be freed, destroy should be set to NULL. The cmp parameter is a valid pointer to a user-defined comparefunc. This function will be used by the Heap data structure to compare it's elements. The order parameter is one of these two values: HEAP_ORDER_CRESCENT, to the heap to store it's elements in crescent order, or HEAP_ORDER_DECRESCENT, to the heap to store it's elements in decrescent order. return value: a pointer to a new Heap data structure, or NULL if the allocation fails. since: YACLib 1.0 int heap_insert(Heap* heap, const void* data) description: inserts an element into the heap specified by heap. The new element stores a pointer to data. return value: 0 if the element could be inserted, -1 otherwise; since: YACLib 1.0 int heap_remove(Heap* heap, void** data) description: removes the first element from the heap specified by heap. Upon return, data will point to the data stored in the element that was removed. return value: 0 if the element could be removed, -1 otherwise; since: YACLib 1.0 void heap_destroy(Heap* heap) description: destroys the heap specified by heap. It will remove all the elements of the heap and call the destroyfunc function passed to heap_create for each element as it is removed from the heap, provided destroy wasn 't set to NULL. return value: none. since: YACLib 1.0 |