24 RCSIDH(minmax_heap_h,
"$Id: 4f0fcd55c6a25890c9b7e24c67eea81d19c3f611 $")
30 #include <freeradius-devel/build.h>
31 #include <freeradius-devel/missing.h>
32 #include <freeradius-devel/util/talloc.h>
35 #include <sys/types.h>
42 #define FR_MINMAX_HEAP_TALLOC_HEADERS 2
70 #define fr_minmax_heap_alloc(_ctx, _cmp, _type, _field, _init) \
71 _fr_minmax_heap_alloc(_ctx, _cmp, NULL, (size_t)offsetof(_type, _field), _init)
85 #define fr_minmax_heap_talloc_alloc(_ctx, _cmp, _talloc_type, _field, _init) \
86 _fr_minmax_heap_alloc(_ctx, _cmp, #_talloc_type, (size_t)offsetof(_talloc_type, _field), _init)
95 return (heap_idx > 0);
124 #define fr_minmax_heap_foreach(_hp, _type, _data) \
126 fr_minmax_heap_iter_t _iter; \
127 for (_type *_data = fr_minmax_heap_iter_init(_hp, &_iter); _data; _data = fr_minmax_heap_iter_next(_hp, &_iter))
129 #ifndef TALLOC_GET_TYPE_ABORT_NOOP
131 # define FR_MINMAX_HEAP_VERIFY(_hp) fr_minmax_heap_verify(__FILE__, __LINE__, _hp)
132 #elif !defined(NDEBUG)
133 # define FR_MINMAX_HEAP_VERIFY(_hp) fr_assert(_hp)
135 # define FR_MINMAX_HEAP_VERIFY(_hp)
fr_minmax_heap_cmp_t cmp
Comparator function.
size_t offset
Offset of heap index in element structure.
int fr_minmax_heap_insert(fr_minmax_heap_t *hp, void *data)
size_t fr_minmax_heap_pre_alloc_size(unsigned int count)
struct fr_minmax_heap_s * fr_minmax_heap_t
The main minmax heap structure Note that fr_minmax_heap_t is a pointer to fr_minmax_heap_s.
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.
void * fr_minmax_heap_min_peek(fr_minmax_heap_t *hp)
int8_t(* fr_minmax_heap_cmp_t)(void const *a, void const *b)
Comparator to order elements.
uint32_t fr_minmax_heap_num_elements(fr_minmax_heap_t *hp)
Return the number of elements in the minmax heap.
static bool fr_minmax_heap_entry_inserted(fr_minmax_heap_index_t heap_idx)
Check if an entry is inserted into a heap.
void * fr_minmax_heap_max_pop(fr_minmax_heap_t *hp)
void * fr_minmax_heap_min_pop(fr_minmax_heap_t *hp)
unsigned int fr_minmax_heap_iter_t
void * fr_minmax_heap_max_peek(fr_minmax_heap_t *hp)
fr_minmax_heap_t * _fr_minmax_heap_alloc(TALLOC_CTX *ctx, fr_minmax_heap_cmp_t cmp, char const *talloc_type, size_t offset, unsigned int init))
unsigned int fr_minmax_heap_index_t
int fr_minmax_heap_extract(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.
void fr_minmax_heap_verify(char const *file, int line, fr_minmax_heap_t const *hp)
init
Enter the EAP-IDENTITY state.