The FreeRADIUS server
$Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
|
Structures and prototypes for binary min-max heaps. More...
#include <freeradius-devel/build.h>
#include <freeradius-devel/missing.h>
#include <freeradius-devel/util/talloc.h>
#include <stdint.h>
#include <sys/types.h>
Go to the source code of this file.
Macros | |
#define | fr_minmax_heap_alloc(_ctx, _cmp, _type, _field, _init) _fr_minmax_heap_alloc(_ctx, _cmp, NULL, (size_t)offsetof(_type, _field), _init) |
Creates a minmax heap that can be used with non-talloced elements. More... | |
#define | fr_minmax_heap_foreach(_hp, _type, _data) |
Iterate over the contents of a minmax_heap. More... | |
#define | fr_minmax_heap_talloc_alloc(_ctx, _cmp, _talloc_type, _field, _init) _fr_minmax_heap_alloc(_ctx, _cmp, #_talloc_type, (size_t)offsetof(_talloc_type, _field), _init) |
Creates a minmax heap that verifies elements are of a specific talloc type. More... | |
#define | FR_MINMAX_HEAP_TALLOC_HEADERS 2 |
How many talloc headers need to be pre-allocated for a minmax heap. More... | |
#define | FR_MINMAX_HEAP_VERIFY(_hp) fr_minmax_heap_verify(__FILE__, __LINE__, _hp) |
Typedefs | |
typedef int8_t(* | fr_minmax_heap_cmp_t) (void const *a, void const *b) |
Comparator to order elements. More... | |
typedef unsigned int | fr_minmax_heap_index_t |
typedef unsigned int | fr_minmax_heap_iter_t |
typedef 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. More... | |
Structures and prototypes for binary min-max heaps.
Definition in file minmax_heap.h.
#define fr_minmax_heap_alloc | ( | _ctx, | |
_cmp, | |||
_type, | |||
_field, | |||
_init | |||
) | _fr_minmax_heap_alloc(_ctx, _cmp, NULL, (size_t)offsetof(_type, _field), _init) |
Creates a minmax heap that can be used with non-talloced elements.
[in] | _ctx | Talloc ctx to allocate heap in. |
[in] | _cmp | Comparator used to compare elements. |
[in] | _type | Of elements. |
[in] | _field | to store heap indexes in. |
[in] | _init | the initial number of elements to allocate. Pass 0 to use the default. |
Definition at line 70 of file minmax_heap.h.
#define fr_minmax_heap_foreach | ( | _hp, | |
_type, | |||
_data | |||
) |
Iterate over the contents of a minmax_heap.
[in] | _hp | to iterate over. |
[in] | _type | of item the heap contains. |
[in] | _data | Name of variable holding a pointer to the heap element. Will be declared in the scope of the loop. |
Definition at line 124 of file minmax_heap.h.
#define fr_minmax_heap_talloc_alloc | ( | _ctx, | |
_cmp, | |||
_talloc_type, | |||
_field, | |||
_init | |||
) | _fr_minmax_heap_alloc(_ctx, _cmp, #_talloc_type, (size_t)offsetof(_talloc_type, _field), _init) |
Creates a minmax heap that verifies elements are of a specific talloc type.
[in] | _ctx | Talloc ctx to allocate heap in. |
[in] | _cmp | Comparator used to compare elements. |
[in] | _talloc_type | of elements. |
[in] | _field | to store heap indexes in. |
[in] | _init | the initial number of elements to allocate. Pass 0 to use the default. |
Definition at line 85 of file minmax_heap.h.
#define FR_MINMAX_HEAP_TALLOC_HEADERS 2 |
How many talloc headers need to be pre-allocated for a minmax heap.
Definition at line 42 of file minmax_heap.h.
#define FR_MINMAX_HEAP_VERIFY | ( | _hp | ) | fr_minmax_heap_verify(__FILE__, __LINE__, _hp) |
Definition at line 131 of file minmax_heap.h.
typedef int8_t(* fr_minmax_heap_cmp_t) (void const *a, void const *b) |
Comparator to order elements.
Return a negative number if 'a' precedes 'b'. Return zero if the ordering of 'a' and 'b' doesn't matter. Return a positive number if 'b' precedes 'a'.
Definition at line 50 of file minmax_heap.h.
typedef unsigned int fr_minmax_heap_index_t |
Definition at line 37 of file minmax_heap.h.
typedef unsigned int fr_minmax_heap_iter_t |
Definition at line 38 of file minmax_heap.h.
typedef 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.
This added level of indirection lets one allocate/reallocate the heap structure and the array of pointers to items in the minmax heap as a unit without affecting the caller.
Definition at line 57 of file minmax_heap.h.
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 | ||
) |
|
inlinestatic |
Check if an entry is inserted into a heap.
Definition at line 93 of file minmax_heap.h.
int fr_minmax_heap_extract | ( | fr_minmax_heap_t * | hp, |
void * | data | ||
) |
Definition at line 486 of file minmax_heap.c.
int fr_minmax_heap_insert | ( | fr_minmax_heap_t * | hp, |
void * | data | ||
) |
Definition at line 424 of file minmax_heap.c.
void* fr_minmax_heap_iter_init | ( | fr_minmax_heap_t * | hp, |
fr_minmax_heap_iter_t * | iter | ||
) |
Iterate over entries in a minmax heap.
[in] | hp | to iterate over. |
[in] | iter | Pointer to an iterator struct, used to maintain state between calls. |
Definition at line 551 of file minmax_heap.c.
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.
[in] | hp | to iterate over. |
[in] | iter | Pointer to an iterator struct, used to maintain state between calls. |
Definition at line 573 of file minmax_heap.c.
void* fr_minmax_heap_max_peek | ( | fr_minmax_heap_t * | hp | ) |
void* fr_minmax_heap_max_pop | ( | fr_minmax_heap_t * | hp | ) |
Definition at line 477 of file minmax_heap.c.
void* fr_minmax_heap_min_peek | ( | fr_minmax_heap_t * | hp | ) |
void* fr_minmax_heap_min_pop | ( | fr_minmax_heap_t * | hp | ) |
Definition at line 457 of file minmax_heap.c.
uint32_t fr_minmax_heap_num_elements | ( | fr_minmax_heap_t * | hp | ) |
Return the number of elements in the minmax heap.
[in] | hp | to return the number of elements from. |
Definition at line 533 of file minmax_heap.c.
size_t fr_minmax_heap_pre_alloc_size | ( | unsigned int | count | ) |
void fr_minmax_heap_verify | ( | char const * | file, |
int | line, | ||
fr_minmax_heap_t const * | hp | ||
) |