23 RCSID(
"$Id: 2e4c500dc484a79b6673fbd84284744521ecd5e3 $")
25 #define _HEAP_PRIVATE 1
26 #include <freeradius-devel/util/debug.h>
27 #include <freeradius-devel/util/heap.h>
28 #include <freeradius-devel/util/misc.h>
29 #include <freeradius-devel/util/strerror.h>
31 #define INITIAL_CAPACITY 2048
38 #define HEAP_PARENT(_x) ((_x) >> 1)
39 #define HEAP_LEFT(_x) (2 * (_x))
40 #define HEAP_RIGHT(_x) (2 * (_x) + 1 )
41 #define HEAP_SWAP(_a, _b) do { void *_tmp = _a; _a = _b; _b = _tmp; } while (0)
87 h->
p[0] = (
void *)UINTPTR_MAX;
102 #define OFFSET_SET(_heap, _idx) index_set(_heap, _heap->p[_idx], _idx)
103 #define OFFSET_RESET(_heap, _idx) index_set(_heap, _heap->p[_idx], 0)
105 static inline CC_HINT(always_inline)
113 n_size, (n_size * (
unsigned int)
sizeof(
void *)));
164 #ifndef TALLOC_GET_TYPE_ABORT_NOOP
165 if (h->
type) (void)_talloc_get_type_abort(
data, h->
type, __location__);
171 if (child > h->
size) {
181 if (h->
size == UINT_MAX) {
188 n_size = h->
size * 2;
271 while (child <= max) {
275 if ((child != max) &&
276 (h->
cmp(h->
p[child + 1], h->
p[child]) < 0)) {
379 #ifndef TALLOC_GET_TYPE_ABORT_NOOP
383 (void) talloc_get_type_abort(h,
fr_heap_t);
392 (void) talloc_get_type_abort(h,
fr_heap_t);
395 "CONSISTENCY CHECK FAILED %s[%i]: num_elements exceeds size",
file,
line);
398 "CONSISTENCY CHECK FAILED %s[%i]: zeroeth element special value overwritten",
file,
line);
401 void *
data = h->
p[i];
404 if (h->
type) (void)_talloc_get_type_abort(
data, h->
type, __location__);
406 "CONSISTENCY CHECK FAILED %s[%i]: node %u index != %u",
file,
line, i, i);
408 for (
unsigned int i = 1; ; i++) {
411 "CONSISTENCY_CHECK_FAILED %s[%i]: node %u > left child",
file,
line, i);
414 "CONSISTENCY_CHECK_FAILED %s[%i]: node %u > right child",
file,
line, i);
#define fr_cond_assert(_x)
Calls panic_action ifndef NDEBUG, else logs error and evaluates to value of _x.
#define fr_fatal_assert_msg(_x, _fmt,...)
Calls panic_action ifndef NDEBUG, else logs error and causes the server to exit immediately with code...
#define OFFSET_SET(_heap, _idx)
static void index_set(fr_heap_t *h, void *data, fr_heap_index_t idx)
void * fr_heap_pop(fr_heap_t **hp)
Remove a node from the heap.
static fr_heap_index_t index_get(fr_heap_t *h, void *data)
fr_heap_t * _fr_heap_alloc(TALLOC_CTX *ctx, fr_heap_cmp_t cmp, char const *type, size_t offset, unsigned int init)
#define OFFSET_RESET(_heap, _idx)
static int realloc_heap(fr_heap_t **hp, unsigned int n_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.
int fr_heap_insert(fr_heap_t **hp, void *data)
Insert a new element into the heap.
void * fr_heap_iter_init(fr_heap_t *h, fr_heap_iter_t *iter)
Iterate over entries in heap.
#define HEAP_SWAP(_a, _b)
int fr_heap_extract(fr_heap_t **hp, void *data)
Remove a node from the heap.
static void fr_heap_bubble(fr_heap_t *h, fr_heap_index_t child)
void fr_heap_verify(char const *file, int line, fr_heap_t *h)
void * fr_heap_iter_next(fr_heap_t *h, fr_heap_iter_t *iter)
Get the next entry in a heap.
unsigned int fr_heap_index_t
char const *_CONST type
Talloc type of elements.
unsigned int _CONST min
Minimum number of elements we allow the heap to reduce down to.
unsigned int fr_heap_iter_t
unsigned int _CONST size
Number of nodes allocated.
unsigned int _CONST num_elements
Number of nodes used.
static bool fr_heap_entry_inserted(fr_heap_index_t heap_idx)
Check if an entry is inserted into a heap.
void *_CONST p[]
Array of nodes.
fr_heap_cmp_t _CONST cmp
Comparator function.
#define FR_HEAP_INDEX_INVALID
int8_t(* fr_heap_cmp_t)(void const *a, void const *b)
Comparator to order heap elements.
size_t _CONST offset
Offset of heap index in element structure.
#define ROUND_UP_DIV(_x, _y)
Get the ceiling value of integer division.
init
Enter the EAP-IDENTITY state.
fr_aka_sim_id_type_t type
#define fr_strerror_printf(_fmt,...)
Log to thread local error buffer.
#define fr_strerror_const(_msg)