Defines | |
#define | BINARY_HEAP_NULL ((void *) 0) |
A null BinaryHeapValue. | |
Typedefs | |
typedef void * | BinaryHeapValue |
A value stored in a BinaryHeap. | |
typedef int(* | BinaryHeapCompareFunc )(BinaryHeapValue value1, BinaryHeapValue value2) |
Type of function used to compare values in a binary heap. | |
typedef struct _BinaryHeap | BinaryHeap |
A binary heap data structure. | |
Enumerations | |
enum | BinaryHeapType { BINARY_HEAP_TYPE_MIN, BINARY_HEAP_TYPE_MAX } |
Heap type. More... | |
Functions | |
BinaryHeap * | binary_heap_new (BinaryHeapType heap_type, BinaryHeapCompareFunc compare_func) |
Create a new BinaryHeap. | |
void | binary_heap_free (BinaryHeap *heap) |
Destroy a binary heap. | |
int | binary_heap_insert (BinaryHeap *heap, BinaryHeapValue value) |
Insert a value into a binary heap. | |
BinaryHeapValue | binary_heap_pop (BinaryHeap *heap) |
Remove the first value from a binary heap. | |
int | binary_heap_num_entries (BinaryHeap *heap) |
Find the number of values stored in a binary heap. |
A binary heap is a heap data structure implemented using a binary tree. In a heap, values are ordered by priority.
To create a binary heap, use binary_heap_new. To destroy a binary heap, use binary_heap_free.
To insert a value into a binary heap, use binary_heap_insert.
To remove the first value from a binary heap, use binary_heap_pop.
typedef int(* BinaryHeapCompareFunc)(BinaryHeapValue value1, BinaryHeapValue value2) |
Type of function used to compare values in a binary heap.
value1 | The first value. | |
value2 | The second value. |
enum BinaryHeapType |
Heap type.
If a heap is a min heap (BINARY_HEAP_TYPE_MIN), the values with the lowest priority are stored at the top of the heap and will be the first returned. If a heap is a max heap (BINARY_HEAP_TYPE_MAX), the values with the greatest priority are stored at the top of the heap.
void binary_heap_free | ( | BinaryHeap * | heap | ) |
Destroy a binary heap.
heap | The heap to destroy. |
int binary_heap_insert | ( | BinaryHeap * | heap, | |
BinaryHeapValue | value | |||
) |
Insert a value into a binary heap.
heap | The heap to insert into. | |
value | The value to insert. |
BinaryHeap* binary_heap_new | ( | BinaryHeapType | heap_type, | |
BinaryHeapCompareFunc | compare_func | |||
) |
Create a new BinaryHeap.
heap_type | The type of heap: min heap or max heap. | |
compare_func | Pointer to a function used to compare the priority of values in the heap. |
int binary_heap_num_entries | ( | BinaryHeap * | heap | ) |
Find the number of values stored in a binary heap.
heap | The heap. |
BinaryHeapValue binary_heap_pop | ( | BinaryHeap * | heap | ) |
Remove the first value from a binary heap.
heap | The heap. |