Creates a new #EggHeap. A heap is a tree-like structure stored in
an array that is not fully sorted, but head is guaranteed to be either
the max, or min value based on compare_func
. This is also known as
a priority queue.
the size of each element in the heap
a function to compare to elements
Decrements the reference count of heap
by one, freeing the structure
when the reference count reaches zero.
Creates a new #EggHeap. A heap is a tree-like structure stored in
an array that is not fully sorted, but head is guaranteed to be either
the max, or min value based on compare_func
. This is also known as
a priority queue.
the size of each element in the heap
a function to compare to elements
Heaps are similar to a partially sorted tree but implemented as an array. They allow for efficient O(1) lookup of the highest priority item as it will always be the first item of the array.
To create a new heap use egg_heap_new().
To add items to the heap, use egg_heap_insert_val() or egg_heap_insert_vals() to insert in bulk.
To access an item in the heap, use egg_heap_index().
To remove an arbitrary item from the heap, use egg_heap_extract_index().
To remove the highest priority item in the heap, use egg_heap_extract().
To free a heap, use egg_heap_unref().
Here is an example that stores integers in a #EggHeap: