Functions for a minmax heap.
More...
#include <freeradius-devel/util/minmax_heap.h>
#include <freeradius-devel/util/strerror.h>
#include <freeradius-devel/util/debug.h>
#include <freeradius-devel/util/misc.h>
Go to the source code of this file.
|
fr_minmax_heap_t * | _fr_minmax_heap_alloc (TALLOC_CTX *ctx, fr_minmax_heap_cmp_t cmp, char const *type, size_t offset, unsigned int init) |
|
static uint8_t | depth (fr_minmax_heap_index_t i) |
|
int | fr_minmax_heap_extract (fr_minmax_heap_t *hp, void *data) |
|
int | fr_minmax_heap_insert (fr_minmax_heap_t *hp, void *data) |
|
void * | fr_minmax_heap_iter_init (fr_minmax_heap_t *hp, fr_minmax_heap_iter_t *iter) |
| Iterate over entries in a minmax heap. More...
|
|
void * | fr_minmax_heap_iter_next (fr_minmax_heap_t *hp, fr_minmax_heap_iter_t *iter) |
| Get the next entry in a minmax heap. More...
|
|
void * | fr_minmax_heap_max_peek (fr_minmax_heap_t *hp) |
|
void * | fr_minmax_heap_max_pop (fr_minmax_heap_t *hp) |
|
void * | fr_minmax_heap_min_peek (fr_minmax_heap_t *hp) |
|
void * | fr_minmax_heap_min_pop (fr_minmax_heap_t *hp) |
|
unsigned int | fr_minmax_heap_num_elements (fr_minmax_heap_t *hp) |
| Return the number of elements in the minmax heap. More...
|
|
void | fr_minmax_heap_verify (char const *file, int line, fr_minmax_heap_t const *hp) |
|
static bool | has_children (minmax_heap_t *h, fr_minmax_heap_index_t idx) |
|
static bool | has_grandchildren (minmax_heap_t *h, fr_minmax_heap_index_t i) |
|
static fr_minmax_heap_index_t | index_get (minmax_heap_t *h, void *data) |
|
static void | index_set (minmax_heap_t *h, void *data, fr_minmax_heap_index_t idx) |
|
static bool | is_descendant (fr_minmax_heap_index_t candidate, fr_minmax_heap_index_t ancestor) |
|
static bool | is_min_level_index (fr_minmax_heap_index_t i) |
|
static fr_minmax_heap_index_t | max_child_or_grandchild (minmax_heap_t *h, fr_minmax_heap_index_t idx) |
|
static fr_minmax_heap_index_t | min_child_or_grandchild (minmax_heap_t *h, fr_minmax_heap_index_t idx) |
| Find the index of the minimum child or grandchild of the entry at a given index. More...
|
|
static int | minmax_heap_expand (fr_minmax_heap_t *hp) |
|
static void | push_down (minmax_heap_t *h, fr_minmax_heap_index_t idx) |
|
static void | push_down_max (minmax_heap_t *h, fr_minmax_heap_index_t idx) |
| precondition: idx is the index of an existing entry on a max level (Just like push_down_min() save for reversal of ordering, so comments there apply, mutatis mutandis.) More...
|
|
static void | push_down_min (minmax_heap_t *h, fr_minmax_heap_index_t idx) |
| precondition: idx is the index of an existing entry on a min level More...
|
|
static void | push_up (minmax_heap_t *h, fr_minmax_heap_index_t idx) |
|
static void | push_up_max (minmax_heap_t *h, fr_minmax_heap_index_t idx) |
|
static void | push_up_min (minmax_heap_t *h, fr_minmax_heap_index_t idx) |
|
Functions for a minmax heap.
- Copyright
- 2021 Network RADIUS SAS (legal.nosp@m.@net.nosp@m.workr.nosp@m.adiu.nosp@m.s.com)
Definition in file minmax_heap.c.
◆ fr_minmax_heap_s
Definition at line 53 of file minmax_heap.c.
Data Fields |
fr_minmax_heap_cmp_t |
cmp |
Comparator function. |
unsigned int |
num_elements |
Number of nodes used. |
size_t |
offset |
Offset of heap index in element structure. |
void * |
p[] |
Array of nodes. |
unsigned int |
size |
Number of nodes allocated. |
char const * |
type |
Talloc type of elements. |
◆ HEAP_GRANDPARENT
◆ HEAP_LEFT
#define HEAP_LEFT |
( |
|
_x | ) |
(2 * (_x)) |
◆ HEAP_PARENT
#define HEAP_PARENT |
( |
|
_x | ) |
((_x) >> 1) |
◆ HEAP_RIGHT
#define HEAP_RIGHT |
( |
|
_x | ) |
(2 * (_x) + 1 ) |
◆ HEAP_SWAP
#define HEAP_SWAP |
( |
|
_a, |
|
|
|
_b |
|
) |
| do { void *_tmp = _a; _a = _b; _b = _tmp; } while (0) |
◆ INITIAL_CAPACITY
◆ is_max_level_index
◆ OFFSET_RESET
◆ OFFSET_SET
◆ minmax_heap_t
◆ _fr_minmax_heap_alloc()
◆ depth()
◆ fr_minmax_heap_extract()
◆ fr_minmax_heap_insert()
◆ fr_minmax_heap_iter_init()
Iterate over entries in a minmax heap.
- Note
- If the heap is modified the iterator should be considered invalidated.
- Parameters
-
[in] | hp | to iterate over. |
[in] | iter | Pointer to an iterator struct, used to maintain state between calls. |
- Returns
- User data.
- NULL if at the end of the list.
Definition at line 551 of file minmax_heap.c.
◆ fr_minmax_heap_iter_next()
Get the next entry in a minmax heap.
- Note
- If the heap is modified the iterator should be considered invalidated.
- Parameters
-
[in] | hp | to iterate over. |
[in] | iter | Pointer to an iterator struct, used to maintain state between calls. |
- Returns
- User data.
- NULL if at the end of the list.
Definition at line 573 of file minmax_heap.c.
◆ fr_minmax_heap_max_peek()
◆ fr_minmax_heap_max_pop()
◆ fr_minmax_heap_min_peek()
◆ fr_minmax_heap_min_pop()
◆ fr_minmax_heap_num_elements()
Return the number of elements in the minmax heap.
- Parameters
-
[in] | hp | to return the number of elements from. |
Definition at line 533 of file minmax_heap.c.
◆ fr_minmax_heap_verify()
void fr_minmax_heap_verify |
( |
char const * |
file, |
|
|
int |
line, |
|
|
fr_minmax_heap_t const * |
hp |
|
) |
| |
◆ has_children()
◆ has_grandchildren()
◆ index_get()
◆ index_set()
◆ is_descendant()
◆ is_min_level_index()
◆ max_child_or_grandchild()
◆ min_child_or_grandchild()
Find the index of the minimum child or grandchild of the entry at a given index.
precondition: has_children(h, idx), i.e. there is stuff in the heap below idx.
These functions are called by push_down_{min, max}() with idx the index of an element moved into that position but which may or may not be where it should ultimately go. The minmax heap property still holds for its (positional, at least) descendants, though. That lets us cut down on the number of comparisons over brute force iteration over every child and grandchild.
In the case where the desired item must be a child, there are at most two, so we just do it inlne; no loop needed.
Definition at line 237 of file minmax_heap.c.
◆ minmax_heap_expand()
◆ push_down()
◆ push_down_max()
precondition: idx is the index of an existing entry on a max level (Just like push_down_min() save for reversal of ordering, so comments there apply, mutatis mutandis.)
Definition at line 332 of file minmax_heap.c.
◆ push_down_min()
precondition: idx is the index of an existing entry on a min level
Definition at line 302 of file minmax_heap.c.
◆ push_up()
◆ push_up_max()
◆ push_up_min()