|
C Fundamentals
Algorithms · data structures · cryptography · systems — pure C11, zero deps
|
Go to the source code of this file.
Classes | |
| struct | heap |
Macros | |
| #define | HEAP_INITIAL_CAP 16 |
Functions | |
| void | heap_build_min (int *arr, size_t n) |
| heap_t * | heap_create (void) |
| void | heap_destroy (heap_t *h) |
| bool | heap_extract_min (heap_t *h, int *out_value) |
| static bool | heap_grow (heap_t *h) |
| bool | heap_insert (heap_t *h, int value) |
| bool | heap_is_empty (const heap_t *h) |
| bool | heap_peek_min (const heap_t *h, int *out_value) |
| void | heap_sift_down_max (int *arr, size_t i, size_t n) |
| size_t | heap_size (const heap_t *h) |
| static void | sift_down_min (int *arr, size_t i, size_t n) |
| static void | sift_up_min (int *arr, size_t i) |
| static void | swap (int *a, int *b) |
| void heap_build_min | ( | int * | arr, |
| size_t | n | ||
| ) |
Build a min-heap from an existing array in O(n). The array is reordered in place.
Definition at line 94 of file heap.c.
References sift_down_min().
| heap_t * heap_create | ( | void | ) |
Definition at line 18 of file heap.c.
References heap::capacity, heap::data, HEAP_INITIAL_CAP, and heap::size.
| void heap_destroy | ( | heap_t * | h | ) |
Definition at line 28 of file heap.c.
References heap::data.
| bool heap_extract_min | ( | heap_t * | h, |
| int * | out_value | ||
| ) |
Definition at line 74 of file heap.c.
References heap::data, sift_down_min(), and heap::size.
|
static |
Definition at line 34 of file heap.c.
References heap::capacity, and heap::data.
Referenced by heap_insert().
| bool heap_insert | ( | heap_t * | h, |
| int | value | ||
| ) |
Definition at line 65 of file heap.c.
References heap::capacity, heap::data, heap_grow(), sift_up_min(), and heap::size.
| bool heap_is_empty | ( | const heap_t * | h | ) |
Definition at line 92 of file heap.c.
References heap::size.
| bool heap_peek_min | ( | const heap_t * | h, |
| int * | out_value | ||
| ) |
Definition at line 85 of file heap.c.
References heap::data, and heap::size.
| void heap_sift_down_max | ( | int * | arr, |
| size_t | i, | ||
| size_t | n | ||
| ) |
Sift-down at index i for an n-element array — exposed for heap sort.
Definition at line 103 of file heap.c.
References swap().
Referenced by heap_sort_ints().
| size_t heap_size | ( | const heap_t * | h | ) |
Definition at line 91 of file heap.c.
References heap::size.
|
static |
Definition at line 52 of file heap.c.
References swap().
Referenced by heap_build_min(), and heap_extract_min().
|
static |
|
static |
Definition at line 16 of file heap.c.
Referenced by heap_sift_down_max(), sift_down_min(), and sift_up_min().