LibJuno 0.42.0
LibJuno is a lightweight C99 library designed specifically for embedded systems.
Loading...
Searching...
No Matches
juno_heap.c File Reference
#include "juno/ds/heap_api.h"
#include "juno/macros.h"
#include "juno/status.h"
Include dependency graph for juno_heap.c:

Functions

JUNO_STATUS_T JunoDs_Heap_Update (JUNO_DS_HEAP_ROOT_T *ptHeap)
 Bubble-up the last inserted element to restore the heap property.
 
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.
 

Function Documentation

◆ JunoDs_Heap_SiftDown()

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:

  • Used internally by Delete and Heapify. You can also call it directly if you overwrite the root or another node and need to restore ordering.

Returns:

  • JUNO_STATUS_SUCCESS on success.
  • JUNO_STATUS_ERR if zLength == 0, if child indices exceed capacity, or if Compare/Swap report an error.

◆ JunoDs_Heap_Update()

JUNO_STATUS_T JunoDs_Heap_Update ( JUNO_DS_HEAP_ROOT_T ptHeap)

Bubble-up the last inserted element to restore the heap property.

Typical usage:

  • After JunoDs_Heap_Insert(...), write your element to the returned index, then call Update to reposition it upward as needed.

Returns:

  • JUNO_STATUS_SUCCESS on success.
  • JUNO_STATUS_ERR if zLength == 0, if Compare fails, if Swap fails, or if the computed parent index would exceed zCapacity. See tests/test_heap.c.