Functions for a basic binary heaps.
More...
#include <freeradius-devel/util/debug.h>
#include <freeradius-devel/util/heap.h>
#include <freeradius-devel/util/misc.h>
#include <freeradius-devel/util/strerror.h>
Go to the source code of this file.
|
fr_heap_t * | _fr_heap_alloc (TALLOC_CTX *ctx, fr_heap_cmp_t cmp, char const *type, size_t offset, unsigned int init) |
|
static void | fr_heap_bubble (fr_heap_t *h, fr_heap_index_t child) |
|
int | fr_heap_extract (fr_heap_t **hp, void *data) |
| Remove a node from the heap. More...
|
|
int | fr_heap_insert (fr_heap_t **hp, void *data) |
| Insert a new element into the heap. More...
|
|
void * | fr_heap_iter_init (fr_heap_t *h, fr_heap_iter_t *iter) |
| Iterate over entries in heap. More...
|
|
void * | fr_heap_iter_next (fr_heap_t *h, fr_heap_iter_t *iter) |
| Get the next entry in a heap. More...
|
|
void * | fr_heap_pop (fr_heap_t **hp) |
| Remove a node from the heap. More...
|
|
size_t | fr_heap_pre_alloc_size (unsigned int count) |
| Return how many bytes need to be allocated to hold a heap of a given size. More...
|
|
void | fr_heap_verify (char const *file, int line, fr_heap_t *h) |
|
static fr_heap_index_t | index_get (fr_heap_t *h, void *data) |
|
static void | index_set (fr_heap_t *h, void *data, fr_heap_index_t idx) |
|
static int | realloc_heap (fr_heap_t **hp, unsigned int n_size) |
|
Functions for a basic binary heaps.
- Copyright
- 2005,2006 The FreeRADIUS server project
Definition in file heap.c.
◆ _HEAP_PRIVATE
◆ 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
◆ OFFSET_RESET
◆ OFFSET_SET
◆ _fr_heap_alloc()
◆ fr_heap_bubble()
◆ fr_heap_extract()
int fr_heap_extract |
( |
fr_heap_t ** |
hp, |
|
|
void * |
data |
|
) |
| |
Remove a node from the heap.
- Parameters
-
[in,out] | hp | The heap to extract an element from. A new pointer value will be written to hp if the heap is resized. |
[in] | data | Data to extract from the heap. |
- Returns
- 0 on success.
- -1 on failure (no elements or data not found).
Definition at line 239 of file heap.c.
◆ fr_heap_insert()
int fr_heap_insert |
( |
fr_heap_t ** |
hp, |
|
|
void * |
data |
|
) |
| |
Insert a new element into the heap.
Insert element in heap. Normally, p != NULL, we insert p in a new position and bubble up. If p == NULL, then the element is already in place, and key is the position where to start the bubble-up.
Returns -1 on failure (cannot allocate new heap entry)
If offset > 0 the position (index, int) of the element in the heap is also stored in the element itself at the given offset in bytes.
- Parameters
-
[in,out] | hp | The heap to extract an element from. A new pointer value will be written to hp if the heap is resized. |
[in] | data | Data to insert into the heap. |
- Returns
- 0 on success.
- -1 on failure (heap full or malloc error).
Definition at line 146 of file heap.c.
◆ fr_heap_iter_init()
Iterate over entries in heap.
- Note
- If the heap is modified the iterator should be considered invalidated.
- Parameters
-
[in] | h | 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 351 of file heap.c.
◆ fr_heap_iter_next()
Get the next entry in a heap.
- Note
- If the heap is modified the iterator should be considered invalidated.
- Parameters
-
[in] | h | 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 371 of file heap.c.
◆ fr_heap_pop()
Remove a node from the heap.
- Parameters
-
[in,out] | hp | The heap to pop an element from. A new pointer value will be written to hp if the heap is resized. |
- Returns
- The item that was popped.
- NULL on error.
Definition at line 322 of file heap.c.
◆ fr_heap_pre_alloc_size()
size_t fr_heap_pre_alloc_size |
( |
unsigned int |
count | ) |
|
Return how many bytes need to be allocated to hold a heap of a given size.
This is useful for passing to talloc[_zero]_pooled_object to avoid additional mallocs.
- Parameters
-
[in] | count | The initial element count. |
- Returns
- The number of bytes to pre-allocate.
Definition at line 52 of file heap.c.
◆ fr_heap_verify()
void fr_heap_verify |
( |
char const * |
file, |
|
|
int |
line, |
|
|
fr_heap_t * |
h |
|
) |
| |
◆ index_get()
◆ index_set()
◆ realloc_heap()
static int realloc_heap |
( |
fr_heap_t ** |
hp, |
|
|
unsigned int |
n_size |
|
) |
| |
|
inlinestatic |