sphinx.addnodesdocument)}( rawsourcechildren]( translations LanguagesNode)}(hhh](h pending_xref)}(hhh]docutils.nodesTextChinese (Simplified)}parenthsba attributes}(ids]classes]names]dupnames]backrefs] refdomainstdreftypedoc reftarget%/translations/zh_CN/core-api/min_heapmodnameN classnameN refexplicitutagnamehhh ubh)}(hhh]hChinese (Traditional)}hh2sbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget%/translations/zh_TW/core-api/min_heapmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hItalian}hhFsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget%/translations/it_IT/core-api/min_heapmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hJapanese}hhZsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget%/translations/ja_JP/core-api/min_heapmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hKorean}hhnsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget%/translations/ko_KR/core-api/min_heapmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hSpanish}hhsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget%/translations/sp_SP/core-api/min_heapmodnameN classnameN refexplicituh1hhh ubeh}(h]h ]h"]h$]h&]current_languageEnglishuh1h hh _documenthsourceNlineNubhcomment)}(h SPDX-License-Identifier: GPL-2.0h]h SPDX-License-Identifier: GPL-2.0}hhsbah}(h]h ]h"]h$]h&] xml:spacepreserveuh1hhhhhh?/var/lib/git/docbuild/linux/Documentation/core-api/min_heap.rsthKubhsection)}(hhh](htitle)}(h Min Heap APIh]h Min Heap API}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhhhhhKubh field_list)}(hhh]hfield)}(hhh](h field_name)}(hAuthorh]hAuthor}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhhhKubh field_body)}(h%Kuan-Wei Chiu h]h paragraph)}(h$Kuan-Wei Chiu h](hKuan-Wei Chiu <}(hhhhhNhNubh reference)}(hvisitorckw@gmail.comh]hvisitorckw@gmail.com}(hhhhhNhNubah}(h]h ]h"]h$]h&]refurimailto:visitorckw@gmail.comuh1hhhubh>}(hhhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhhubah}(h]h ]h"]h$]h&]uh1hhhubeh}(h]h ]h"]h$]h&]uh1hhhhKhhhhubah}(h]h ]h"]h$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(h Introductionh]h Introduction}(hj$hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj!hhhhhK ubh)}(hXThe Min Heap API provides a set of functions and macros for managing min-heaps in the Linux kernel. A min-heap is a binary tree structure where the value of each node is less than or equal to the values of its children, ensuring that the smallest element is always at the root.h]hXThe Min Heap API provides a set of functions and macros for managing min-heaps in the Linux kernel. A min-heap is a binary tree structure where the value of each node is less than or equal to the values of its children, ensuring that the smallest element is always at the root.}(hj2hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK hj!hhubh)}(hThis document provides a guide to the Min Heap API, detailing how to define and use min-heaps. Users should not directly call functions with **__min_heap_*()** prefixes, but should instead use the provided macro wrappers.h](hThis document provides a guide to the Min Heap API, detailing how to define and use min-heaps. Users should not directly call functions with }(hj@hhhNhNubhstrong)}(h**__min_heap_*()**h]h__min_heap_*()}(hjJhhhNhNubah}(h]h ]h"]h$]h&]uh1jHhj@ubh> prefixes, but should instead use the provided macro wrappers.}(hj@hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhj!hhubh)}(hXIn addition to the standard version of the functions, the API also includes a set of inline versions for performance-critical scenarios. These inline functions have the same names as their non-inline counterparts but include an **_inline** suffix. For example, **__min_heap_init_inline** and its corresponding macro wrapper **min_heap_init_inline**. The inline versions allow custom comparison and swap functions to be called directly, rather than through indirect function calls. This can significantly reduce overhead, especially when CONFIG_MITIGATION_RETPOLINE is enabled, as indirect function calls become more expensive. As with the non-inline versions, it is important to use the macro wrappers for inline functions instead of directly calling the functions themselves.h](hIn addition to the standard version of the functions, the API also includes a set of inline versions for performance-critical scenarios. These inline functions have the same names as their non-inline counterparts but include an }(hjbhhhNhNubjI)}(h **_inline**h]h_inline}(hjjhhhNhNubah}(h]h ]h"]h$]h&]uh1jHhjbubh suffix. For example, }(hjbhhhNhNubjI)}(h**__min_heap_init_inline**h]h__min_heap_init_inline}(hj|hhhNhNubah}(h]h ]h"]h$]h&]uh1jHhjbubh% and its corresponding macro wrapper }(hjbhhhNhNubjI)}(h**min_heap_init_inline**h]hmin_heap_init_inline}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jHhjbubhX. The inline versions allow custom comparison and swap functions to be called directly, rather than through indirect function calls. This can significantly reduce overhead, especially when CONFIG_MITIGATION_RETPOLINE is enabled, as indirect function calls become more expensive. As with the non-inline versions, it is important to use the macro wrappers for inline functions instead of directly calling the functions themselves.}(hjbhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhj!hhubeh}(h] introductionah ]h"] introductionah$]h&]uh1hhhhhhhhK ubh)}(hhh](h)}(hData Structuresh]hData Structures}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhK"ubh)}(hhh](h)}(hMin-Heap Definitionh]hMin-Heap Definition}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhK%ubh)}(hThe core data structure for representing a min-heap is defined using the **MIN_HEAP_PREALLOCATED** and **DEFINE_MIN_HEAP** macros. These macros allow you to define a min-heap with a preallocated buffer or dynamically allocated memory.h](hIThe core data structure for representing a min-heap is defined using the }(hjhhhNhNubjI)}(h**MIN_HEAP_PREALLOCATED**h]hMIN_HEAP_PREALLOCATED}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jHhjubh and }(hjhhhNhNubjI)}(h**DEFINE_MIN_HEAP**h]hDEFINE_MIN_HEAP}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jHhjubhp macros. These macros allow you to define a min-heap with a preallocated buffer or dynamically allocated memory.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK'hjhhubh)}(hExample:h]hExample:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK,hjhhubh literal_block)}(hX#define MIN_HEAP_PREALLOCATED(_type, _name, _nr) struct _name { size_t nr; /* Number of elements in the heap */ size_t size; /* Maximum number of elements that can be held */ _type *data; /* Pointer to the heap data */ _type preallocated[_nr]; /* Static preallocated array */ } #define DEFINE_MIN_HEAP(_type, _name) MIN_HEAP_PREALLOCATED(_type, _name, 0)h]hX#define MIN_HEAP_PREALLOCATED(_type, _name, _nr) struct _name { size_t nr; /* Number of elements in the heap */ size_t size; /* Maximum number of elements that can be held */ _type *data; /* Pointer to the heap data */ _type preallocated[_nr]; /* Static preallocated array */ } #define DEFINE_MIN_HEAP(_type, _name) MIN_HEAP_PREALLOCATED(_type, _name, 0)}hjsbah}(h]h ]h"]h$]h&]hhforcelanguagechighlight_args}uh1jhhhK.hjhhubh)}(hXA typical heap structure will include a counter for the number of elements (`nr`), the maximum capacity of the heap (`size`), and a pointer to an array of elements (`data`). Optionally, you can specify a static array for preallocated heap storage using **MIN_HEAP_PREALLOCATED**.h](hLA typical heap structure will include a counter for the number of elements (}(hj%hhhNhNubhtitle_reference)}(h`nr`h]hnr}(hj/hhhNhNubah}(h]h ]h"]h$]h&]uh1j-hj%ubh%), the maximum capacity of the heap (}(hj%hhhNhNubj.)}(h`size`h]hsize}(hjAhhhNhNubah}(h]h ]h"]h$]h&]uh1j-hj%ubh*), and a pointer to an array of elements (}(hj%hhhNhNubj.)}(h`data`h]hdata}(hjShhhNhNubah}(h]h ]h"]h$]h&]uh1j-hj%ubhR). Optionally, you can specify a static array for preallocated heap storage using }(hj%hhhNhNubjI)}(h**MIN_HEAP_PREALLOCATED**h]hMIN_HEAP_PREALLOCATED}(hjehhhNhNubah}(h]h ]h"]h$]h&]uh1jHhj%ubh.}(hj%hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK:hjhhubeh}(h]min-heap-definitionah ]h"]min-heap definitionah$]h&]uh1hhjhhhhhK%ubh)}(hhh](h)}(hMin Heap Callbacksh]hMin Heap Callbacks}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhK@ubh)}(hThe **struct min_heap_callbacks** provides customization options for ordering elements in the heap and swapping them. It contains two function pointers:h](hThe }(hjhhhNhNubjI)}(h**struct min_heap_callbacks**h]hstruct min_heap_callbacks}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jHhjubhw provides customization options for ordering elements in the heap and swapping them. It contains two function pointers:}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKBhjhhubj)}(hstruct min_heap_callbacks { bool (*less)(const void *lhs, const void *rhs, void *args); void (*swp)(void *lhs, void *rhs, void *args); };h]hstruct min_heap_callbacks { bool (*less)(const void *lhs, const void *rhs, void *args); void (*swp)(void *lhs, void *rhs, void *args); };}hjsbah}(h]h ]h"]h$]h&]hhj j!j"j#}uh1jhhhKEhjhhubh bullet_list)}(hhh](h list_item)}(hL**less** is the comparison function used to establish the order of elements.h]h)}(hjh](jI)}(h**less**h]hless}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jHhjubhD is the comparison function used to establish the order of elements.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKLhjubah}(h]h ]h"]h$]h&]uh1jhjhhhhhNubj)}(h**swp** is a function for swapping elements in the heap. If swp is set to NULL, the default swap function will be used, which swaps the elements based on their size h]h)}(h**swp** is a function for swapping elements in the heap. If swp is set to NULL, the default swap function will be used, which swaps the elements based on their sizeh](jI)}(h**swp**h]hswp}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jHhjubh is a function for swapping elements in the heap. If swp is set to NULL, the default swap function will be used, which swaps the elements based on their size}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKMhjubah}(h]h ]h"]h$]h&]uh1jhjhhhhhNubeh}(h]h ]h"]h$]h&]bullet-uh1jhhhKLhjhhubeh}(h]min-heap-callbacksah ]h"]min heap callbacksah$]h&]uh1hhjhhhhhK@ubeh}(h]data-structuresah ]h"]data structuresah$]h&]uh1hhhhhhhhK"ubh)}(hhh](h)}(hMacro Wrappersh]hMacro Wrappers}(hj2hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj/hhhhhKQubh)}(hThe following macro wrappers are provided for interacting with the heap in a user-friendly manner. Each macro corresponds to a function that operates on the heap, and they abstract away direct calls to internal functions.h]hThe following macro wrappers are provided for interacting with the heap in a user-friendly manner. Each macro corresponds to a function that operates on the heap, and they abstract away direct calls to internal functions.}(hj@hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKShj/hhubh)}(h>Each macro accepts various parameters that are detailed below.h]h>Each macro accepts various parameters that are detailed below.}(hjNhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKWhj/hhubh)}(hhh](h)}(hHeap Initializationh]hHeap Initialization}(hj_hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj\hhhhhKZubj)}(h min_heap_init(heap, data, size);h]h min_heap_init(heap, data, size);}hjmsbah}(h]h ]h"]h$]h&]hhj j!j"j#}uh1jhhhK\hj\hhubj)}(hhh](j)}(h@**heap**: A pointer to the min-heap structure to be initialized.h]h)}(hjh](jI)}(h**heap**h]hheap}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jHhjubh8: A pointer to the min-heap structure to be initialized.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK`hjubah}(h]h ]h"]h$]h&]uh1jhj|hhhhhNubj)}(h**data**: A pointer to the buffer where the heap elements will be stored. If `NULL`, the preallocated buffer within the heap structure will be used.h]h)}(h**data**: A pointer to the buffer where the heap elements will be stored. If `NULL`, the preallocated buffer within the heap structure will be used.h](jI)}(h**data**h]hdata}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jHhjubhE: A pointer to the buffer where the heap elements will be stored. If }(hjhhhNhNubj.)}(h`NULL`h]hNULL}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j-hjubhA, the preallocated buffer within the heap structure will be used.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKahjubah}(h]h ]h"]h$]h&]uh1jhj|hhhhhNubj)}(h<**size**: The maximum number of elements the heap can hold. h]h)}(h;**size**: The maximum number of elements the heap can hold.h](jI)}(h**size**h]hsize}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jHhjubh3: The maximum number of elements the heap can hold.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKchjubah}(h]h ]h"]h$]h&]uh1jhj|hhhhhNubeh}(h]h ]h"]h$]h&]jjuh1jhhhK`hj\hhubh)}(hThis macro initializes the heap, setting its initial state. If `data` is `NULL`, the preallocated memory inside the heap structure will be used for storage. Otherwise, the user-provided buffer is used. The operation is **O(1)**.h](h?This macro initializes the heap, setting its initial state. If }(hjhhhNhNubj.)}(h`data`h]hdata}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j-hjubh is }(hjhhhNhNubj.)}(h`NULL`h]hNULL}(hj"hhhNhNubah}(h]h ]h"]h$]h&]uh1j-hjubh, the preallocated memory inside the heap structure will be used for storage. Otherwise, the user-provided buffer is used. The operation is }(hjhhhNhNubjI)}(h**O(1)**h]hO(1)}(hj4hhhNhNubah}(h]h ]h"]h$]h&]uh1jHhjubh.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKehj\hhubh)}(h:**Inline Version:** min_heap_init_inline(heap, data, size)h](jI)}(h**Inline Version:**h]hInline Version:}(hjPhhhNhNubah}(h]h ]h"]h$]h&]uh1jHhjLubh' min_heap_init_inline(heap, data, size)}(hjLhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKihj\hhubeh}(h]heap-initializationah ]h"]heap initializationah$]h&]uh1hhj/hhhhhKZubh)}(hhh](h)}(hAccessing the Top Elementh]hAccessing the Top Element}(hjshhhNhNubah}(h]h ]h"]h$]h&]uh1hhjphhhhhKlubj)}(helement = min_heap_peek(heap);h]helement = min_heap_peek(heap);}hjsbah}(h]h ]h"]h$]h&]hhj j!j"j#}uh1jhhhKnhjphhubj)}(hhh]j)}(hQ**heap**: A pointer to the min-heap from which to retrieve the smallest element. h]h)}(hP**heap**: A pointer to the min-heap from which to retrieve the smallest element.h](jI)}(h**heap**h]hheap}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jHhjubhH: A pointer to the min-heap from which to retrieve the smallest element.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKrhjubah}(h]h ]h"]h$]h&]uh1jhjhhhhhNubah}(h]h ]h"]h$]h&]jjuh1jhhhKrhjphhubh)}(hThis macro returns a pointer to the smallest element (the root) of the heap, or `NULL` if the heap is empty. The operation is **O(1)**.h](hPThis macro returns a pointer to the smallest element (the root) of the heap, or }(hjhhhNhNubj.)}(h`NULL`h]hNULL}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j-hjubh( if the heap is empty. The operation is }(hjhhhNhNubjI)}(h**O(1)**h]hO(1)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jHhjubh.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKuhjphhubh)}(h.**Inline Version:** min_heap_peek_inline(heap)h](jI)}(h**Inline Version:**h]hInline Version:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jHhjubh min_heap_peek_inline(heap)}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKxhjphhubeh}(h]accessing-the-top-elementah ]h"]accessing the top elementah$]h&]uh1hhj/hhhhhKlubh)}(hhh](h)}(hHeap Insertionh]hHeap Insertion}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhK{ubj)}(h8success = min_heap_push(heap, element, callbacks, args);h]h8success = min_heap_push(heap, element, callbacks, args);}hj&sbah}(h]h ]h"]h$]h&]hhj j!j"j#}uh1jhhhK}hjhhubj)}(hhh](j)}(hN**heap**: A pointer to the min-heap into which the element should be inserted.h]h)}(hj:h](jI)}(h**heap**h]hheap}(hj?hhhNhNubah}(h]h ]h"]h$]h&]uh1jHhj<ubhF: A pointer to the min-heap into which the element should be inserted.}(hj<hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhj8ubah}(h]h ]h"]h$]h&]uh1jhj5hhhhhNubj)}(hC**element**: A pointer to the element to be inserted into the heap.h]h)}(hj_h](jI)}(h **element**h]helement}(hjdhhhNhNubah}(h]h ]h"]h$]h&]uh1jHhjaubh8: A pointer to the element to be inserted into the heap.}(hjahhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhj]ubah}(h]h ]h"]h$]h&]uh1jhj5hhhhhNubj)}(hc**callbacks**: A pointer to a `struct min_heap_callbacks` providing the `less` and `swp` functions.h]h)}(hc**callbacks**: A pointer to a `struct min_heap_callbacks` providing the `less` and `swp` functions.h](jI)}(h **callbacks**h]h callbacks}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jHhjubh: A pointer to a }(hjhhhNhNubj.)}(h`struct min_heap_callbacks`h]hstruct min_heap_callbacks}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j-hjubh providing the }(hjhhhNhNubj.)}(h`less`h]hless}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j-hjubh and }(hjhhhNhNubj.)}(h`swp`h]hswp}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j-hjubh functions.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1jhj5hhhhhNubj)}(hG**args**: Optional arguments passed to the `less` and `swp` functions. h]h)}(hF**args**: Optional arguments passed to the `less` and `swp` functions.h](jI)}(h**args**h]hargs}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jHhjubh#: Optional arguments passed to the }(hjhhhNhNubj.)}(h`less`h]hless}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j-hjubh and }(hjhhhNhNubj.)}(h`swp`h]hswp}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1j-hjubh functions.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1jhj5hhhhhNubeh}(h]h ]h"]h$]h&]jjuh1jhhhKhjhhubh)}(hThis macro inserts an element into the heap. It returns `true` if the insertion was successful and `false` if the heap is full. The operation is **O(log n)**.h](h8This macro inserts an element into the heap. It returns }(hj.hhhNhNubj.)}(h`true`h]htrue}(hj6hhhNhNubah}(h]h ]h"]h$]h&]uh1j-hj.ubh% if the insertion was successful and }(hj.hhhNhNubj.)}(h`false`h]hfalse}(hjHhhhNhNubah}(h]h ]h"]h$]h&]uh1j-hj.ubh' if the heap is full. The operation is }(hj.hhhNhNubjI)}(h **O(log n)**h]hO(log n)}(hjZhhhNhNubah}(h]h ]h"]h$]h&]uh1jHhj.ubh.}(hj.hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hH**Inline Version:** min_heap_push_inline(heap, element, callbacks, args)h](jI)}(h**Inline Version:**h]hInline Version:}(hjvhhhNhNubah}(h]h ]h"]h$]h&]uh1jHhjrubh5 min_heap_push_inline(heap, element, callbacks, args)}(hjrhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjhhubeh}(h]heap-insertionah ]h"]heap insertionah$]h&]uh1hhj/hhhhhK{ubh)}(hhh](h)}(h Heap Removalh]h Heap Removal}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhKubj)}(h.success = min_heap_pop(heap, callbacks, args);h]h.success = min_heap_pop(heap, callbacks, args);}hjsbah}(h]h ]h"]h$]h&]hhj j!j"j#}uh1jhhhKhjhhubj)}(hhh](j)}(hN**heap**: A pointer to the min-heap from which to remove the smallest element.h]h)}(hjh](jI)}(h**heap**h]hheap}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jHhjubhF: A pointer to the min-heap from which to remove the smallest element.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1jhjhhhhhNubj)}(hc**callbacks**: A pointer to a `struct min_heap_callbacks` providing the `less` and `swp` functions.h]h)}(hc**callbacks**: A pointer to a `struct min_heap_callbacks` providing the `less` and `swp` functions.h](jI)}(h **callbacks**h]h callbacks}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jHhjubh: A pointer to a }(hjhhhNhNubj.)}(h`struct min_heap_callbacks`h]hstruct min_heap_callbacks}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j-hjubh providing the }(hjhhhNhNubj.)}(h`less`h]hless}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1j-hjubh and }(hjhhhNhNubj.)}(h`swp`h]hswp}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j-hjubh functions.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1jhjhhhhhNubj)}(hG**args**: Optional arguments passed to the `less` and `swp` functions. h]h)}(hF**args**: Optional arguments passed to the `less` and `swp` functions.h](jI)}(h**args**h]hargs}(hjBhhhNhNubah}(h]h ]h"]h$]h&]uh1jHhj>ubh#: Optional arguments passed to the }(hj>hhhNhNubj.)}(h`less`h]hless}(hjThhhNhNubah}(h]h ]h"]h$]h&]uh1j-hj>ubh and }(hj>hhhNhNubj.)}(h`swp`h]hswp}(hjfhhhNhNubah}(h]h ]h"]h$]h&]uh1j-hj>ubh functions.}(hj>hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhj:ubah}(h]h ]h"]h$]h&]uh1jhjhhhhhNubeh}(h]h ]h"]h$]h&]jjuh1jhhhKhjhhubh)}(hThis macro removes the smallest element (the root) from the heap. It returns `true` if the element was successfully removed, or `false` if the heap is empty. The operation is **O(log n)**.h](hMThis macro removes the smallest element (the root) from the heap. It returns }(hjhhhNhNubj.)}(h`true`h]htrue}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j-hjubh- if the element was successfully removed, or }(hjhhhNhNubj.)}(h`false`h]hfalse}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j-hjubh( if the heap is empty. The operation is }(hjhhhNhNubjI)}(h **O(log n)**h]hO(log n)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jHhjubh.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(h>**Inline Version:** min_heap_pop_inline(heap, callbacks, args)h](jI)}(h**Inline Version:**h]hInline Version:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jHhjubh+ min_heap_pop_inline(heap, callbacks, args)}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjhhubeh}(h] heap-removalah ]h"] heap removalah$]h&]uh1hhj/hhhhhKubh)}(hhh](h)}(hHeap Maintenanceh]hHeap Maintenance}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhKubh)}(hBYou can use the following macros to maintain the heap's structure:h]hDYou can use the following macros to maintain the heap’s structure:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubj)}(h/min_heap_sift_down(heap, pos, callbacks, args);h]h/min_heap_sift_down(heap, pos, callbacks, args);}hjsbah}(h]h ]h"]h$]h&]hhj j!j"j#}uh1jhhhKhjhhubj)}(hhh](j)}(h$**heap**: A pointer to the min-heap.h]h)}(hj%h](jI)}(h**heap**h]hheap}(hj*hhhNhNubah}(h]h ]h"]h$]h&]uh1jHhj'ubh: A pointer to the min-heap.}(hj'hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhj#ubah}(h]h ]h"]h$]h&]uh1jhj hhhhhNubj)}(h4**pos**: The index from which to start sifting down.h]h)}(hjJh](jI)}(h**pos**h]hpos}(hjOhhhNhNubah}(h]h ]h"]h$]h&]uh1jHhjLubh-: The index from which to start sifting down.}(hjLhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjHubah}(h]h ]h"]h$]h&]uh1jhj hhhhhNubj)}(hc**callbacks**: A pointer to a `struct min_heap_callbacks` providing the `less` and `swp` functions.h]h)}(hc**callbacks**: A pointer to a `struct min_heap_callbacks` providing the `less` and `swp` functions.h](jI)}(h **callbacks**h]h callbacks}(hjuhhhNhNubah}(h]h ]h"]h$]h&]uh1jHhjqubh: A pointer to a }(hjqhhhNhNubj.)}(h`struct min_heap_callbacks`h]hstruct min_heap_callbacks}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j-hjqubh providing the }(hjqhhhNhNubj.)}(h`less`h]hless}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j-hjqubh and }(hjqhhhNhNubj.)}(h`swp`h]hswp}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j-hjqubh functions.}(hjqhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjmubah}(h]h ]h"]h$]h&]uh1jhj hhhhhNubj)}(hG**args**: Optional arguments passed to the `less` and `swp` functions. h]h)}(hF**args**: Optional arguments passed to the `less` and `swp` functions.h](jI)}(h**args**h]hargs}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jHhjubh#: Optional arguments passed to the }(hjhhhNhNubj.)}(h`less`h]hless}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j-hjubh and }(hjhhhNhNubj.)}(h`swp`h]hswp}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j-hjubh functions.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1jhj hhhhhNubeh}(h]h ]h"]h$]h&]jjuh1jhhhKhjhhubh)}(hThis macro restores the heap property by moving the element at the specified index (`pos`) down the heap until it is in the correct position. The operation is **O(log n)**.h](hTThis macro restores the heap property by moving the element at the specified index (}(hj hhhNhNubj.)}(h`pos`h]hpos}(hj! hhhNhNubah}(h]h ]h"]h$]h&]uh1j-hj ubhF) down the heap until it is in the correct position. The operation is }(hj hhhNhNubjI)}(h **O(log n)**h]hO(log n)}(hj3 hhhNhNubah}(h]h ]h"]h$]h&]uh1jHhj ubh.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hI**Inline Version:** min_heap_sift_down_inline(heap, pos, callbacks, args)h](jI)}(h**Inline Version:**h]hInline Version:}(hjO hhhNhNubah}(h]h ]h"]h$]h&]uh1jHhjK ubh6 min_heap_sift_down_inline(heap, pos, callbacks, args)}(hjK hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjhhubj)}(h-min_heap_sift_up(heap, idx, callbacks, args);h]h-min_heap_sift_up(heap, idx, callbacks, args);}hjg sbah}(h]h ]h"]h$]h&]hhj j!j"j#}uh1jhhhKhjhhubj)}(hhh](j)}(h$**heap**: A pointer to the min-heap.h]h)}(hj{ h](jI)}(h**heap**h]hheap}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jHhj} ubh: A pointer to the min-heap.}(hj} hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjy ubah}(h]h ]h"]h$]h&]uh1jhjv hhhhhNubj)}(h-**idx**: The index of the element to sift up.h]h)}(hj h](jI)}(h**idx**h]hidx}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jHhj ubh&: The index of the element to sift up.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhj ubah}(h]h ]h"]h$]h&]uh1jhjv hhhhhNubj)}(hc**callbacks**: A pointer to a `struct min_heap_callbacks` providing the `less` and `swp` functions.h]h)}(hc**callbacks**: A pointer to a `struct min_heap_callbacks` providing the `less` and `swp` functions.h](jI)}(h **callbacks**h]h callbacks}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jHhj ubh: A pointer to a }(hj hhhNhNubj.)}(h`struct min_heap_callbacks`h]hstruct min_heap_callbacks}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1j-hj ubh providing the }(hj hhhNhNubj.)}(h`less`h]hless}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1j-hj ubh and }(hj hhhNhNubj.)}(h`swp`h]hswp}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1j-hj ubh functions.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhj ubah}(h]h ]h"]h$]h&]uh1jhjv hhhhhNubj)}(hG**args**: Optional arguments passed to the `less` and `swp` functions. h]h)}(hF**args**: Optional arguments passed to the `less` and `swp` functions.h](jI)}(h**args**h]hargs}(hj' hhhNhNubah}(h]h ]h"]h$]h&]uh1jHhj# ubh#: Optional arguments passed to the }(hj# hhhNhNubj.)}(h`less`h]hless}(hj9 hhhNhNubah}(h]h ]h"]h$]h&]uh1j-hj# ubh and }(hj# hhhNhNubj.)}(h`swp`h]hswp}(hjK hhhNhNubah}(h]h ]h"]h$]h&]uh1j-hj# ubh functions.}(hj# hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhj ubah}(h]h ]h"]h$]h&]uh1jhjv hhhhhNubeh}(h]h ]h"]h$]h&]jjuh1jhhhKhjhhubh)}(hThis macro restores the heap property by moving the element at the specified index (`idx`) up the heap. The operation is **O(log n)**.h](hTThis macro restores the heap property by moving the element at the specified index (}(hjo hhhNhNubj.)}(h`idx`h]hidx}(hjw hhhNhNubah}(h]h ]h"]h$]h&]uh1j-hjo ubh ) up the heap. The operation is }(hjo hhhNhNubjI)}(h **O(log n)**h]hO(log n)}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jHhjo ubh.}(hjo hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hG**Inline Version:** min_heap_sift_up_inline(heap, idx, callbacks, args)h](jI)}(h**Inline Version:**h]hInline Version:}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jHhj ubh4 min_heap_sift_up_inline(heap, idx, callbacks, args)}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjhhubj)}(h'min_heapify_all(heap, callbacks, args);h]h'min_heapify_all(heap, callbacks, args);}hj sbah}(h]h ]h"]h$]h&]hhj j!j"j#}uh1jhhhKhjhhubj)}(hhh](j)}(h$**heap**: A pointer to the min-heap.h]h)}(hj h](jI)}(h**heap**h]hheap}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jHhj ubh: A pointer to the min-heap.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhj ubah}(h]h ]h"]h$]h&]uh1jhj hhhhhNubj)}(hc**callbacks**: A pointer to a `struct min_heap_callbacks` providing the `less` and `swp` functions.h]h)}(hc**callbacks**: A pointer to a `struct min_heap_callbacks` providing the `less` and `swp` functions.h](jI)}(h **callbacks**h]h callbacks}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jHhj ubh: A pointer to a }(hj hhhNhNubj.)}(h`struct min_heap_callbacks`h]hstruct min_heap_callbacks}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1j-hj ubh providing the }(hj hhhNhNubj.)}(h`less`h]hless}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1j-hj ubh and }(hj hhhNhNubj.)}(h`swp`h]hswp}(hj2 hhhNhNubah}(h]h ]h"]h$]h&]uh1j-hj ubh functions.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhj ubah}(h]h ]h"]h$]h&]uh1jhj hhhhhNubj)}(hG**args**: Optional arguments passed to the `less` and `swp` functions. h]h)}(hF**args**: Optional arguments passed to the `less` and `swp` functions.h](jI)}(h**args**h]hargs}(hjX hhhNhNubah}(h]h ]h"]h$]h&]uh1jHhjT ubh#: Optional arguments passed to the }(hjT hhhNhNubj.)}(h`less`h]hless}(hjj hhhNhNubah}(h]h ]h"]h$]h&]uh1j-hjT ubh and }(hjT hhhNhNubj.)}(h`swp`h]hswp}(hj| hhhNhNubah}(h]h ]h"]h$]h&]uh1j-hjT ubh functions.}(hjT hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjP ubah}(h]h ]h"]h$]h&]uh1jhj hhhhhNubeh}(h]h ]h"]h$]h&]jjuh1jhhhKhjhhubh)}(hThis macro ensures that the entire heap satisfies the heap property. It is called when the heap is built from scratch or after many modifications. The operation is **O(n)**.h](hThis macro ensures that the entire heap satisfies the heap property. It is called when the heap is built from scratch or after many modifications. The operation is }(hj hhhNhNubjI)}(h**O(n)**h]hO(n)}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jHhj ubh.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hA**Inline Version:** min_heapify_all_inline(heap, callbacks, args)h](jI)}(h**Inline Version:**h]hInline Version:}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jHhj ubh. min_heapify_all_inline(heap, callbacks, args)}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjhhubeh}(h]heap-maintenanceah ]h"]heap maintenanceah$]h&]uh1hhj/hhhhhKubh)}(hhh](h)}(hRemoving Specific Elementsh]hRemoving Specific Elements}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj hhhhhKubj)}(h3success = min_heap_del(heap, idx, callbacks, args);h]h3success = min_heap_del(heap, idx, callbacks, args);}hj sbah}(h]h ]h"]h$]h&]hhj j!j"j#}uh1jhhhKhj hhubj)}(hhh](j)}(h$**heap**: A pointer to the min-heap.h]h)}(hj h](jI)}(h**heap**h]hheap}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jHhj ubh: A pointer to the min-heap.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhj ubah}(h]h ]h"]h$]h&]uh1jhj hhhhhNubj)}(h,**idx**: The index of the element to delete.h]h)}(hj. h](jI)}(h**idx**h]hidx}(hj3 hhhNhNubah}(h]h ]h"]h$]h&]uh1jHhj0 ubh%: The index of the element to delete.}(hj0 hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhj, ubah}(h]h ]h"]h$]h&]uh1jhj hhhhhNubj)}(hc**callbacks**: A pointer to a `struct min_heap_callbacks` providing the `less` and `swp` functions.h]h)}(hc**callbacks**: A pointer to a `struct min_heap_callbacks` providing the `less` and `swp` functions.h](jI)}(h **callbacks**h]h callbacks}(hjY hhhNhNubah}(h]h ]h"]h$]h&]uh1jHhjU ubh: A pointer to a }(hjU hhhNhNubj.)}(h`struct min_heap_callbacks`h]hstruct min_heap_callbacks}(hjk hhhNhNubah}(h]h ]h"]h$]h&]uh1j-hjU ubh providing the }(hjU hhhNhNubj.)}(h`less`h]hless}(hj} hhhNhNubah}(h]h ]h"]h$]h&]uh1j-hjU ubh and }(hjU hhhNhNubj.)}(h`swp`h]hswp}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1j-hjU ubh functions.}(hjU hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjQ ubah}(h]h ]h"]h$]h&]uh1jhj hhhhhNubj)}(hG**args**: Optional arguments passed to the `less` and `swp` functions. h]h)}(hF**args**: Optional arguments passed to the `less` and `swp` functions.h](jI)}(h**args**h]hargs}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jHhj ubh#: Optional arguments passed to the }(hj hhhNhNubj.)}(h`less`h]hless}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1j-hj ubh and }(hj hhhNhNubj.)}(h`swp`h]hswp}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1j-hj ubh functions.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhj ubah}(h]h ]h"]h$]h&]uh1jhj hhhhhNubeh}(h]h ]h"]h$]h&]jjuh1jhhhKhj hhubh)}(hThis macro removes an element at the specified index (`idx`) from the heap and restores the heap property. The operation is **O(log n)**.h](h6This macro removes an element at the specified index (}(hj hhhNhNubj.)}(h`idx`h]hidx}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1j-hj ubhA) from the heap and restores the heap property. The operation is }(hj hhhNhNubjI)}(h **O(log n)**h]hO(log n)}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jHhj ubh.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhj hhubh)}(hC**Inline Version:** min_heap_del_inline(heap, idx, callbacks, args)h](jI)}(h**Inline Version:**h]hInline Version:}(hj3 hhhNhNubah}(h]h ]h"]h$]h&]uh1jHhj/ ubh0 min_heap_del_inline(heap, idx, callbacks, args)}(hj/ hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhj hhubeh}(h]removing-specific-elementsah ]h"]removing specific elementsah$]h&]uh1hhj/hhhhhKubeh}(h]macro-wrappersah ]h"]macro wrappersah$]h&]uh1hhhhhhhhKQubh)}(hhh](h)}(hOther Utilitiesh]hOther Utilities}(hj^ hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj[ hhhhhKubj)}(hhh]j)}(hP**min_heap_full(heap)**: Checks whether the heap is full. Complexity: **O(1)**. h]h)}(hO**min_heap_full(heap)**: Checks whether the heap is full. Complexity: **O(1)**.h](jI)}(h**min_heap_full(heap)**h]hmin_heap_full(heap)}(hjw hhhNhNubah}(h]h ]h"]h$]h&]uh1jHhjs ubh/: Checks whether the heap is full. Complexity: }(hjs hhhNhNubjI)}(h**O(1)**h]hO(1)}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jHhjs ubh.}(hjs hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjo ubah}(h]h ]h"]h$]h&]uh1jhjl hhhhhNubah}(h]h ]h"]h$]h&]jjuh1jhhhKhj[ hhubj)}(h bool full = min_heap_full(heap);h]h bool full = min_heap_full(heap);}hj sbah}(h]h ]h"]h$]h&]hhj j!j"j#}uh1jhhhKhj[ hhubj)}(hhh]j)}(h,`heap`: A pointer to the min-heap to check. h]h)}(h+`heap`: A pointer to the min-heap to check.h](j.)}(h`heap`h]hheap}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1j-hj ubh%: A pointer to the min-heap to check.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhj ubah}(h]h ]h"]h$]h&]uh1jhj hhhhhNubah}(h]h ]h"]h$]h&]jjuh1jhhhKhj[ hhubh)}(hAThis macro returns `true` if the heap is full, otherwise `false`.h](hThis macro returns }(hj hhhNhNubj.)}(h`true`h]htrue}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1j-hj ubh if the heap is full, otherwise }(hj hhhNhNubj.)}(h`false`h]hfalse}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j-hj ubh.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhj[ hhubh)}(h.**Inline Version:** min_heap_full_inline(heap)h](jI)}(h**Inline Version:**h]hInline Version:}(hj!hhhNhNubah}(h]h ]h"]h$]h&]uh1jHhjubh min_heap_full_inline(heap)}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhj[ hhubj)}(hhh]j)}(hR**min_heap_empty(heap)**: Checks whether the heap is empty. Complexity: **O(1)**. h]h)}(hQ**min_heap_empty(heap)**: Checks whether the heap is empty. Complexity: **O(1)**.h](jI)}(h**min_heap_empty(heap)**h]hmin_heap_empty(heap)}(hjDhhhNhNubah}(h]h ]h"]h$]h&]uh1jHhj@ubh0: Checks whether the heap is empty. Complexity: }(hj@hhhNhNubjI)}(h**O(1)**h]hO(1)}(hjVhhhNhNubah}(h]h ]h"]h$]h&]uh1jHhj@ubh.}(hj@hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhj<ubah}(h]h ]h"]h$]h&]uh1jhj9hhhhhNubah}(h]h ]h"]h$]h&]jjuh1jhhhKhj[ hhubj)}(h"bool empty = min_heap_empty(heap);h]h"bool empty = min_heap_empty(heap);}hjzsbah}(h]h ]h"]h$]h&]hhj j!j"j#}uh1jhhhKhj[ hhubj)}(hhh]j)}(h,`heap`: A pointer to the min-heap to check. h]h)}(h+`heap`: A pointer to the min-heap to check.h](j.)}(h`heap`h]hheap}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j-hjubh%: A pointer to the min-heap to check.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1jhjhhhhhNubah}(h]h ]h"]h$]h&]jjuh1jhhhKhj[ hhubh)}(hBThis macro returns `true` if the heap is empty, otherwise `false`.h](hThis macro returns }(hjhhhNhNubj.)}(h`true`h]htrue}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j-hjubh! if the heap is empty, otherwise }(hjhhhNhNubj.)}(h`false`h]hfalse}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j-hjubh.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhj[ hhubh)}(h/**Inline Version:** min_heap_empty_inline(heap)h](jI)}(h**Inline Version:**h]hInline Version:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jHhjubh min_heap_empty_inline(heap)}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhj[ hhubeh}(h]other-utilitiesah ]h"]other utilitiesah$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(h Example Usageh]h Example Usage}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhMubh)}(hAn example usage of the min-heap API would involve defining a heap structure, initializing it, and inserting and removing elements as needed.h]hAn example usage of the min-heap API would involve defining a heap structure, initializing it, and inserting and removing elements as needed.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubj)}(hX(#include int my_less_function(const void *lhs, const void *rhs, void *args) { return (*(int *)lhs < *(int *)rhs); } struct min_heap_callbacks heap_cb = { .less = my_less_function, /* Comparison function for heap order */ .swp = NULL, /* Use default swap function */ }; void example_usage(void) { /* Pre-populate the buffer with elements */ int buffer[5] = {5, 2, 8, 1, 3}; /* Declare a min-heap */ DEFINE_MIN_HEAP(int, my_heap); /* Initialize the heap with preallocated buffer and size */ min_heap_init(&my_heap, buffer, 5); /* Build the heap using min_heapify_all */ my_heap.nr = 5; /* Set the number of elements in the heap */ min_heapify_all(&my_heap, &heap_cb, NULL); /* Peek at the top element (should be 1 in this case) */ int *top = min_heap_peek(&my_heap); pr_info("Top element: %d\n", *top); /* Pop the top element (1) and get the new top (2) */ min_heap_pop(&my_heap, &heap_cb, NULL); top = min_heap_peek(&my_heap); pr_info("New top element: %d\n", *top); /* Insert a new element (0) and recheck the top */ int new_element = 0; min_heap_push(&my_heap, &new_element, &heap_cb, NULL); top = min_heap_peek(&my_heap); pr_info("Top element after insertion: %d\n", *top); }h]hX(#include int my_less_function(const void *lhs, const void *rhs, void *args) { return (*(int *)lhs < *(int *)rhs); } struct min_heap_callbacks heap_cb = { .less = my_less_function, /* Comparison function for heap order */ .swp = NULL, /* Use default swap function */ }; void example_usage(void) { /* Pre-populate the buffer with elements */ int buffer[5] = {5, 2, 8, 1, 3}; /* Declare a min-heap */ DEFINE_MIN_HEAP(int, my_heap); /* Initialize the heap with preallocated buffer and size */ min_heap_init(&my_heap, buffer, 5); /* Build the heap using min_heapify_all */ my_heap.nr = 5; /* Set the number of elements in the heap */ min_heapify_all(&my_heap, &heap_cb, NULL); /* Peek at the top element (should be 1 in this case) */ int *top = min_heap_peek(&my_heap); pr_info("Top element: %d\n", *top); /* Pop the top element (1) and get the new top (2) */ min_heap_pop(&my_heap, &heap_cb, NULL); top = min_heap_peek(&my_heap); pr_info("New top element: %d\n", *top); /* Insert a new element (0) and recheck the top */ int new_element = 0; min_heap_push(&my_heap, &new_element, &heap_cb, NULL); top = min_heap_peek(&my_heap); pr_info("Top element after insertion: %d\n", *top); }}hj-sbah}(h]h ]h"]h$]h&]hhj j!j"j#}uh1jhhhMhjhhubeh}(h] example-usageah ]h"] example usageah$]h&]uh1hhhhhhhhMubeh}(h] min-heap-apiah ]h"] min heap apiah$]h&]uh1hhhhhhhhKubeh}(h]h ]h"]h$]h&]sourcehuh1hcurrent_sourceN current_lineNsettingsdocutils.frontendValues)}(hN generatorN datestampN source_linkN source_urlN toc_backlinksentryfootnote_backlinksK sectnum_xformKstrip_commentsNstrip_elements_with_classesN strip_classesN report_levelK halt_levelKexit_status_levelKdebugNwarning_streamN tracebackinput_encoding utf-8-siginput_encoding_error_handlerstrictoutput_encodingutf-8output_encoding_error_handlerjoerror_encodingutf-8error_encoding_error_handlerbackslashreplace language_codeenrecord_dependenciesNconfigN id_prefixhauto_id_prefixid dump_settingsNdump_internalsNdump_transformsNdump_pseudo_xmlNexpose_internalsNstrict_visitorN_disable_configN_sourceh _destinationN _config_files]7/var/lib/git/docbuild/linux/Documentation/docutils.confafile_insertion_enabled raw_enabledKline_length_limitM'pep_referencesN pep_base_urlhttps://peps.python.org/pep_file_url_templatepep-%04drfc_referencesN rfc_base_url&https://datatracker.ietf.org/doc/html/ tab_widthKtrim_footnote_reference_spacesyntax_highlightlong smart_quotessmartquotes_locales]character_level_inline_markupdoctitle_xform docinfo_xformKsectsubtitle_xform image_loadinglinkembed_stylesheetcloak_email_addressessection_self_linkenvNubreporterNindirect_targets]substitution_defs}substitution_names}refnames}refids}nameids}(jIjFjjj,j)jjj$j!jX jU jmjjjjjjjjj j jP jM j jjAj>u nametypes}(jIjj,jj$jX jmjjjj jP j jAuh}(jFhjj!j)jjjj!jjU j/jjj\jjpjjjjj jjM j jj[ j>ju footnote_refs} citation_refs} autofootnotes]autofootnote_refs]symbol_footnotes]symbol_footnote_refs] footnotes] citations]autofootnote_startKsymbol_footnote_startK id_counter collectionsCounter}Rparse_messages]transform_messages] transformerN include_log] decorationNhhub.