1 #include <freeradius-devel/util/acutest.h>
2 #include <freeradius-devel/util/time.h>
3 #include <freeradius-devel/util/rand.h>
14 if (h->
p[i + 1] ==
data) {
33 static int8_t
heap_cmp(
void const *one,
void const *two)
40 #define HEAP_TEST_SIZE (4096)
66 printf(
"Array %d has value %d at offset %d\n",
78 TEST_MSG(
"element %i inserted but not in heap", i);
90 TEST_MSG(
"element %i removed out of order", entry);
96 TEST_MSG(
"element %i removed but still in heap", entry);
99 TEST_MSG(
"element %i removed out of order", entry);
104 for (i = 0; i < left; i++) {
109 TEST_MSG(
"expected %i elements remaining in the heap", left - i);
112 TEST_MSG(
"failed extracting %i", i);
116 TEST_MSG(
"%i elements remaining", ret);
137 #define HEAP_CYCLE_SIZE (1600000)
146 unsigned int count = 0;
169 TEST_MSG(
"element %i inserted but not in heap", i);
189 #define HEAP_ITER_SIZE 20
195 unsigned int data_set;
210 data_set |= (1U <<
item->data);
224 int inserted, removed;
226 fr_time_t start_insert, start_remove, start_swap, end;
257 for (i = 0; i < to_remove; i++) {
261 TEST_MSG(
"expected %i elements remaining in the heap", to_remove - i);
#define TEST_MSG_ALWAYS(...)
#define CMP_PREFER_SMALLER(_a, _b)
Evaluates to +1 for a > b, and -1 for a < b.
Functions for a basic binary heaps.
void * fr_heap_pop(fr_heap_t **hp)
Remove a node from the heap.
int fr_heap_insert(fr_heap_t **hp, void *data)
Insert a new element into the heap.
int fr_heap_extract(fr_heap_t **hp, void *data)
Remove a node from the heap.
static void * fr_heap_peek(fr_heap_t *h)
Return the item from the top of the heap but don't pop it.
#define FR_HEAP_VERIFY(_heap)
#define fr_heap_alloc(_ctx, _cmp, _type, _field, _init)
Creates a heap that can be used with non-talloced elements.
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.
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.
#define fr_heap_foreach(_heap, _type, _data)
Iterate over the contents of a heap.
static void heap_test_order(void)
static int8_t heap_cmp(void const *one, void const *two)
static void heap_iter(void)
static void heap_test_skip_0(void)
static void heap_test_skip_10(void)
static void heap_test_skip_2(void)
static void heap_test(int skip)
static bool fr_heap_check(fr_heap_t *h, void *data)
TEST_CHECK(data_set==((1U<< HEAP_ITER_SIZE) - 1U))
static void heap_cycle(void)
static size_t array[MY_ARRAY_SIZE]
uint32_t fr_fast_rand(fr_fast_rand_t *ctx)
uint32_t fr_rand(void)
Return a 32-bit random number.
Smaller fast random number generator.
#define fr_time()
Allow us to arbitrarily manipulate time.
static int64_t fr_time_delta_unwrap(fr_time_delta_t time)
#define fr_time_sub(_a, _b)
Subtract one time from another.
char const * fr_strerror(void)
Get the last library error.