24 RCSIDH(heap_h,
"$Id: 5c615f0e4fee73795140048ce5b2eac2f3fd941f $")
30 #include <freeradius-devel/build.h>
31 #include <freeradius-devel/missing.h>
32 #include <freeradius-devel/util/talloc.h>
35 #include <sys/types.h>
41 # error _CONST can only be defined in the local header
83 #define FR_HEAP_INDEX_INVALID (0)
87 #define FR_HEAP_TALLOC_HEADERS 2
100 #define fr_heap_alloc(_ctx, _cmp, _type, _field, _init) \
101 _fr_heap_alloc(_ctx, _cmp, NULL, (size_t)offsetof(_type, _field), _init)
115 #define fr_heap_talloc_alloc(_ctx, _cmp, _talloc_type, _field, _init) \
116 _fr_heap_alloc(_ctx, _cmp, #_talloc_type, (size_t)offsetof(_talloc_type, _field), _init)
118 size_t offset,
unsigned int init) CC_HINT(
nonnull(2));
205 #define fr_heap_foreach(_heap, _type, _data) \
207 fr_heap_iter_t _iter; \
208 for (_type *_data = fr_heap_iter_init(_heap, &_iter); _data; _data = fr_heap_iter_next(_heap, &_iter))
210 #ifndef TALLOC_GET_TYPE_ABORT_NOOP
212 # define FR_HEAP_VERIFY(_heap) fr_heap_verify(__FILE__, __LINE__, _heap)
213 #elif !defined(NDEBUG)
214 # define FR_HEAP_VERIFY(_heap) fr_assert(_heap)
216 # define FR_HEAP_VERIFY(_heap)
unsigned int fr_heap_index_t
static void * fr_heap_peek(fr_heap_t *h)
Return the item from the top of the heap but don't pop it.
char const *_CONST type
Talloc type of elements.
void * fr_heap_pop(fr_heap_t **hp)
Remove a node from the heap.
void fr_heap_verify(char const *file, int line, fr_heap_t *hp)
static void * fr_heap_peek_at(fr_heap_t *h, fr_heap_index_t idx)
Peek at a specific index in the heap.
unsigned int _CONST min
Minimum number of elements we allow the heap to reduce down to.
static void * fr_heap_peek_tail(fr_heap_t *h)
Peek at the last element in the heap (not necessarily the bottom)
unsigned int fr_heap_iter_t
unsigned int _CONST size
Number of nodes allocated.
void * fr_heap_iter_next(fr_heap_t *hp, fr_heap_iter_t *iter)
Get the next entry in a heap.
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 *hp, fr_heap_iter_t *iter)
Iterate over entries in heap.
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.
int fr_heap_extract(fr_heap_t **hp, void *data)
Remove a node from the heap.
static unsigned int fr_heap_num_elements(fr_heap_t *h)
Return the number of elements in the heap.
void *_CONST p[]
Array of nodes.
fr_heap_cmp_t _CONST cmp
Comparator function.
fr_heap_t * _fr_heap_alloc(TALLOC_CTX *ctx, fr_heap_cmp_t cmp, char const *talloc_type, size_t offset, unsigned int init))
#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.
init
Enter the EAP-IDENTITY state.