GTS Library Reference Manual |
---|
#include <gts.h> struct GtsHeap; GtsHeap* gts_heap_new (GCompareFunc compare_func); void gts_heap_insert (GtsHeap *heap,gpointer p);gpointer gts_heap_remove_top (GtsHeap *heap);gpointer gts_heap_top (GtsHeap *heap); void gts_heap_freeze (GtsHeap *heap); void gts_heap_thaw (GtsHeap *heap); void gts_heap_foreach (GtsHeap *heap,GFunc func,gpointer user_data);guint gts_heap_size (GtsHeap *heap); void gts_heap_destroy (GtsHeap *heap);
The basic operations gts_heap_insert() and gts_heap_remove_top() are performed in O(log n) time. Calling gts_heap_freeze(), inserting elements using gts_heap_insert() and calling gts_heap_thaw() allows to build the binary heap in O(n) time.
GtsHeap* gts_heap_new (GCompareFunc compare_func);
compare_func : | a GCompareFunc. |
Returns : | a new GtsHeap using compare_func as a sorting function. |
void gts_heap_insert (GtsHeap *heap,gpointer p);
Inserts a new element p in the heap.
heap : | a GtsHeap. |
p : | a pointer to add to the heap. |
gpointer gts_heap_remove_top (GtsHeap *heap);
Removes the element at the top of the heap.
heap : | a GtsHeap. |
Returns : | the element at the top of the heap. |
gpointer gts_heap_top (GtsHeap *heap);
heap : | a GtsHeap. |
Returns : | the element at the top of the heap. |
void gts_heap_freeze (GtsHeap *heap);
Freezes the heap. Any subsequent operation will not preserve the heap property. Used in conjunction with gts_heap_insert() and gts_heap_thaw() to create a heap in O(n) time.
heap : | a GtsHeap. |
void gts_heap_thaw (GtsHeap *heap);
If heap has been frozen previously using gts_heap_freeze(), reorder it in O(n) time and unfreeze it.
heap : | a GtsHeap. |
void gts_heap_foreach (GtsHeap *heap,GFunc func,gpointer user_data);
heap : | a GtsHeap. |
func : | the function to call for each element in the heap. |
user_data : | to pass to func. |
guint gts_heap_size (GtsHeap *heap);
heap : | a GtsHeap. |
Returns : | the number of items in heap. |
<<< Basic Macros, functions and data structures | Extended binary heaps >>> |