|
Zephyr API Documentation 4.4.99
A Scalable Open Source RTOS
|
Reference (handle-based) min-heap implementation. More...
Files | |
| file | min_heap_ref.h |
| Header-file for the reference (handle-based) min-heap data structure. | |
Data Structures | |
| struct | min_heap_handle |
| Embeddable heap position handle. More... | |
| struct | min_heap_ref |
| min-heap data structure with user-provided comparator. More... | |
Macros | |
| #define | MIN_HEAP_REF_DEFINE(name, cap, cmp_func) |
| Define a min-heap instance. | |
| #define | MIN_HEAP_REF_DEFINE_STATIC(name, cap, cmp_func) |
| Define a statically allocated min-heap instance. | |
| #define | MIN_HEAP_REF_FOREACH(__heap, __handle) |
| Iterate over every element currently in the min-heap. | |
| #define | MIN_HEAP_REF_FOREACH_CONTAINER(__heap, __cn, __field) |
| Iterate over every element in the min-heap yielding the embedding container struct. | |
Typedefs | |
| typedef int(* | min_heap_ref_cmp_t) (const struct min_heap_handle *a, const struct min_heap_handle *b) |
| Comparator function type for min-heap ordering. | |
Functions | |
| static void | min_heap_ref_init (struct min_heap_ref *heap, struct min_heap_handle **storage, size_t capacity, min_heap_ref_cmp_t cmp) |
| Initialize a min-heap instance at runtime. | |
| static void | min_heap_ref_swap (struct min_heap_ref *heap, size_t a, size_t b) |
| Swap two elements in the heap storage, updating their idx fields. | |
| static void | min_heap_ref_heapify_up (struct min_heap_ref *heap, size_t index) |
| Restore heap order by moving a node up the tree. | |
| static void | min_heap_ref_heapify_down (struct min_heap_ref *heap, size_t index) |
| Restore heap order by moving a node down the tree. | |
| static int | min_heap_ref_push (struct min_heap_ref *heap, struct min_heap_handle *handle) |
| Push a handle into the min-heap. | |
| static const struct min_heap_handle * | min_heap_ref_peek (const struct min_heap_ref *heap) |
| Peek at the top element of the min-heap. | |
| static bool | min_heap_ref_remove (struct min_heap_ref *heap, struct min_heap_handle *handle) |
| Remove a specific element from the min-heap by handle. | |
| static bool | min_heap_ref_is_empty (struct min_heap_ref *heap) |
| Check if the min heap is empty. | |
| static struct min_heap_handle * | min_heap_ref_pop (struct min_heap_ref *heap) |
| Remove and return the highest priority element's handle. | |
Reference (handle-based) min-heap implementation.
A min-heap is a binary tree-based data structure in which the smallest element is always at the root. Unlike the value-based min-heap, this variant stores pointers to caller-owned nodes that embed a min_heap_handle, so insertion is zero-copy and a specific node can be removed in O(log n) using its handle, with no search.
| #define MIN_HEAP_REF_DEFINE | ( | name, | |
| cap, | |||
| cmp_func ) |
#include <zephyr/sys/min_heap_ref.h>
Define a min-heap instance.
| name | Base name for the heap instance. |
| cap | Capacity (number of elements). |
| cmp_func | Comparator function used by the heap |
| #define MIN_HEAP_REF_DEFINE_STATIC | ( | name, | |
| cap, | |||
| cmp_func ) |
#include <zephyr/sys/min_heap_ref.h>
Define a statically allocated min-heap instance.
| name | Base name for the heap instance. |
| cap | Capacity (number of elements). |
| cmp_func | Comparator function used by the heap |
| #define MIN_HEAP_REF_FOREACH | ( | __heap, | |
| __handle ) |
#include <zephyr/sys/min_heap_ref.h>
Iterate over every element currently in the min-heap.
Visits all elements in internal storage-array order (BFS level order). This is NOT the sorted order
Usage:
| __heap | Pointer to the min-heap. |
| __handle | min_heap_handle pointer. |
| #define MIN_HEAP_REF_FOREACH_CONTAINER | ( | __heap, | |
| __cn, | |||
| __field ) |
#include <zephyr/sys/min_heap_ref.h>
Iterate over every element in the min-heap yielding the embedding container struct.
Usage:
| __heap | Pointer to the min-heap |
| __cn | Caller-declared pointer to the container struct type |
| __field | Name of the min_heap_handle member in the container |
| typedef int(* min_heap_ref_cmp_t) (const struct min_heap_handle *a, const struct min_heap_handle *b) |
#include <zephyr/sys/min_heap_ref.h>
Comparator function type for min-heap ordering.
This function compares two heap nodes to establish their relative order. It must be implemented by the user and provided at min-heap initialization.
| a | First handle pointer for comparison. |
| b | Second handle pointer for comparison. |
a is less than b, positive value if a is greater than b, zero if they are equal.
|
inlinestatic |
#include <zephyr/sys/min_heap_ref.h>
Restore heap order by moving a node down the tree.
Moves the node at the sepcified index downward in the heap until the min-heap property is restored.
| heap | Pointer to the min-heap. |
| index | Index of the node to heapify downward. |
|
inlinestatic |
#include <zephyr/sys/min_heap_ref.h>
Restore heap order by moving a node up the tree.
Moves the node at the given index upward in the heap until the min-heap property is restored.
| heap | Pointer to the min-heap. |
| index | Index of the node to heapify upwards. |
|
inlinestatic |
#include <zephyr/sys/min_heap_ref.h>
Initialize a min-heap instance at runtime.
Sets up the internal structure of a min heap using a user-provided handle pointer array, capacity, and comparator function. This function must be called before using the heap if not statically defined.
| heap | Pointer to the min-heap structure. |
| storage | Pointer to array of handle pointers. |
| capacity | Maximum number of elements the heap can store. |
| cmp | Comparator function used to order the heap elements. |
|
inlinestatic |
#include <zephyr/sys/min_heap_ref.h>
Check if the min heap is empty.
This function checks whether the heap contains any elements.
| heap | Pointer to the min heap. |
|
inlinestatic |
#include <zephyr/sys/min_heap_ref.h>
Peek at the top element of the min-heap.
The function will not remove the element from the min-heap.
| heap | Pointer to the min-heap. |
|
inlinestatic |
#include <zephyr/sys/min_heap_ref.h>
Remove and return the highest priority element's handle.
| heap | Pointer to heap. |
|
inlinestatic |
#include <zephyr/sys/min_heap_ref.h>
Push a handle into the min-heap.
Adds a new handle to the min-heap and restores the heap order by moving it upward as necessary. Insert operation will fail if the min-heap has reached full capacity.
| heap | Pointer to the min-heap. |
| handle | Pointer to the handle to insert. |
|
inlinestatic |
#include <zephyr/sys/min_heap_ref.h>
Remove a specific element from the min-heap by handle.
The handle's idx field gives the O(1) location, no linear scan needed.
| heap | Pointer to the min-heap. |
| handle | Handle of the element to remove (must currently be in heap). |
|
inlinestatic |
#include <zephyr/sys/min_heap_ref.h>
Swap two elements in the heap storage, updating their idx fields.
| heap | Pointer to the min-heap. |
| a | Index of the first element. |
| b | Index of the second element. |