ftwin 0.8.10
|
Implementation of the generic binary heap. More...
Go to the source code of this file.
Functions | |
napr_heap_t * | napr_heap_make (apr_pool_t *pool, napr_heap_cmp_callback_fn_t *cmp) |
Creates a new heap. | |
int | napr_heap_insert (napr_heap_t *heap, void *datum) |
Inserts an element into the heap, maintaining the heap property. | |
void * | napr_heap_extract (napr_heap_t *heap) |
Removes and returns the element at the top of the heap (the min or max element). | |
void * | napr_heap_get_nth (const napr_heap_t *heap, unsigned int n) |
Gets the element at a specific index in the heap's internal array. | |
unsigned int | napr_heap_size (const napr_heap_t *heap) |
Gets the current number of elements in the heap. | |
napr_heap_t * | napr_heap_make_r (apr_pool_t *pool, napr_heap_cmp_callback_fn_t *cmp) |
Creates a new thread-safe heap. | |
int | napr_heap_insert_r (napr_heap_t *heap, void *datum) |
Inserts an element into a thread-safe heap. | |
Implementation of the generic binary heap.
Definition in file napr_heap.c.
void * napr_heap_extract | ( | napr_heap_t * | heap | ) |
Removes and returns the element at the top of the heap (the min or max element).
[in] | heap | The heap. |
Definition at line 122 of file napr_heap.c.
Referenced by ft_report_duplicates(), and ft_report_json().
void * napr_heap_get_nth | ( | const napr_heap_t * | heap, |
unsigned int | n | ||
) |
Gets the element at a specific index in the heap's internal array.
[in] | heap | The heap. |
[in] | n | The index. |
Definition at line 173 of file napr_heap.c.
int napr_heap_insert | ( | napr_heap_t * | heap, |
void * | datum | ||
) |
Inserts an element into the heap, maintaining the heap property.
[in] | heap | The heap. |
[in] | datum | The data item to insert. |
Definition at line 70 of file napr_heap.c.
References DEBUG_ERR.
Referenced by napr_heap_insert_r().
int napr_heap_insert_r | ( | napr_heap_t * | heap, |
void * | datum | ||
) |
Inserts an element into a thread-safe heap.
[in] | heap | The thread-safe heap. |
[in] | datum | The data item to insert. |
Definition at line 204 of file napr_heap.c.
References DEBUG_ERR, and napr_heap_insert().
napr_heap_t * napr_heap_make | ( | apr_pool_t * | pool, |
napr_heap_cmp_callback_fn_t * | cmp | ||
) |
Creates a new heap.
A heap is a specialized tree-based data structure that satisfies the heap property: if P is a parent node of C, then the key (the value) of P is either greater than or equal to (in a max heap) or less than or equal to (in a min heap) the key of C. This implementation provides O(log n) time complexity for insertions and O(1) for finding the min/max element.
[in] | pool | The APR pool to use for allocations. |
[in] | cmp | The comparison function that defines the heap order. |
Definition at line 48 of file napr_heap.c.
Referenced by napr_heap_make_r().
napr_heap_t * napr_heap_make_r | ( | apr_pool_t * | pool, |
napr_heap_cmp_callback_fn_t * | cmp | ||
) |
Creates a new thread-safe heap.
[in] | pool | The APR pool to use for allocations. |
[in] | cmp | The comparison function. |
Definition at line 189 of file napr_heap.c.
References napr_heap_make().
unsigned int napr_heap_size | ( | const napr_heap_t * | heap | ) |
Gets the current number of elements in the heap.
[in] | heap | The heap. |
Definition at line 181 of file napr_heap.c.
Referenced by ftwin_main().