|
LibJuno 1.0.1
LibJuno is a lightweight C11 library designed specifically for embedded systems.
|
Data Structures | |
| struct | JUNO_DS_HEAP_POINTER_API_TAG |
| Element-level operations required by the heap. More... | |
| struct | JUNO_DS_HEAP_API_TAG |
| Heap API vtable. More... | |
Functions | |
| struct JUNO_DS_HEAP_ROOT_TAG | JUNO_MODULE_ROOT (JUNO_DS_HEAP_API_T, const JUNO_DS_HEAP_POINTER_API_T *ptHeapPointerApi;JUNO_DS_ARRAY_ROOT_T *ptHeapArray;size_t zLength;) |
| Heap root instance and state. | |
| JUNO_STATUS_T | JunoDs_Heap_Insert (JUNO_DS_HEAP_ROOT_T *ptHeap, JUNO_POINTER_T tValue) |
| Insert a new element into the heap. | |
| JUNO_STATUS_T | JunoDs_Heap_Heapify (JUNO_DS_HEAP_ROOT_T *ptHeap) |
| Transform the underlying array into a heap. | |
| JUNO_STATUS_T | JunoDs_Heap_Pop (JUNO_DS_HEAP_ROOT_T *ptHeap, JUNO_POINTER_T tReturn) |
Pop the root element into tReturn. | |
| JUNO_STATUS_T | JunoDs_Heap_Init (JUNO_DS_HEAP_ROOT_T *ptHeap, const JUNO_DS_HEAP_POINTER_API_T *ptHeapPointerApi, JUNO_DS_ARRAY_ROOT_T *ptHeapArray, JUNO_FAILURE_HANDLER_T pfcnFailureHdlr, JUNO_USER_DATA_T *pvUserData) |
| Initialize a heap over a backing array and element pointer API. | |
| JUNO_STATUS_T | JunoDs_Heap_SiftDown (JUNO_DS_HEAP_ROOT_T *ptHeap, size_t iStart) |
| Sift down from a starting index to restore the heap property. | |
| static JUNO_STATUS_T | JunoDs_Heap_Verify (JUNO_DS_HEAP_ROOT_T *ptHeap) |
| Verify heap configuration and dependent APIs. | |
A binary heap interface parameterized by element-level comparison and swap callbacks over an underlying Array. The heap stores elements in a contiguous array (JUNO_DS_ARRAY_ROOT_T) and maintains either a max-heap or min-heap property depending on the user-provided Compare function.
Characteristics
Invariants (enforced by implementation and Verify):
Ordering semantics:
Element ownership:
| struct JUNO_DS_HEAP_ROOT_TAG JUNO_MODULE_ROOT | ( | JUNO_DS_HEAP_API_T | , |
| const JUNO_DS_HEAP_POINTER_API_T *ptHeapPointerApi;JUNO_DS_ARRAY_ROOT_T *ptHeapArray;size_t zLength; | |||
| ) |
Heap root instance and state.
| JUNO_STATUS_T JunoDs_Heap_Heapify | ( | JUNO_DS_HEAP_ROOT_T * | ptHeap | ) |
Transform the underlying array into a heap.
| ptHeap | Heap instance with zLength set to the count of initialized elements. |
Transform the underlying array into a heap.
Set zLength to the number of initialized elements, then call Heapify.
| JUNO_STATUS_T JunoDs_Heap_Init | ( | JUNO_DS_HEAP_ROOT_T * | ptHeap, |
| const JUNO_DS_HEAP_POINTER_API_T * | ptHeapPointerApi, | ||
| JUNO_DS_ARRAY_ROOT_T * | ptHeapArray, | ||
| JUNO_FAILURE_HANDLER_T | pfcnFailureHdlr, | ||
| JUNO_USER_DATA_T * | pvUserData | ||
| ) |
Initialize a heap over a backing array and element pointer API.
| ptHeap | Heap instance to initialize (output). |
| ptHeapPointerApi | Element-level callbacks (Compare/Swap) defining ordering. |
| ptHeapArray | Backing array providing capacity and element storage ops. |
| pfcnFailureHdlr | Optional failure handler for assertions in this module (can be NULL). |
| pvUserData | Optional user data passed to the failure handler (can be NULL). |
| JUNO_STATUS_T JunoDs_Heap_Insert | ( | JUNO_DS_HEAP_ROOT_T * | ptHeap, |
| JUNO_POINTER_T | tValue | ||
| ) |
Insert a new element into the heap.
| ptHeap | Heap instance. |
| tValue | Pointer descriptor for the element to copy into the heap. |
Insert a new element into the heap.
After a successful insert, you must write the element to the returned index in your storage, then call JunoDs_Heap_Update(...) to bubble it up.
| JUNO_STATUS_T JunoDs_Heap_Pop | ( | JUNO_DS_HEAP_ROOT_T * | ptHeap, |
| JUNO_POINTER_T | tReturn | ||
| ) |
Pop the root element into tReturn.
| ptHeap | Heap instance. |
| tReturn | Pointer descriptor receiving a copy of the popped root value. |
Pop the root element into tReturn.
Algorithm:
Error propagation:
| JUNO_STATUS_T JunoDs_Heap_SiftDown | ( | JUNO_DS_HEAP_ROOT_T * | ptHeap, |
| size_t | iStart | ||
| ) |
Sift down from a starting index to restore the heap property.
Typical usage:
Returns:
Sift the element at iStart downward until the heap property holds.
| ptHeap | Heap instance. |
| iStart | Start index for sifting (commonly 0 after a pop). |
|
inlinestatic |
Verify heap configuration and dependent APIs.
Ensures the heap instance and all required API pointers are set, then delegates to JunoDs_ArrayVerify for the backing array. Used by all heap operations to guard preconditions.