3#include <freeradius-devel/util/rand.h>
4#include <freeradius-devel/util/time.h>
5#include <freeradius-devel/util/heap.h>
21static void lst_validate(
fr_lst_t *lst);
28 for (
unsigned int i = 0; i < size; i++)
if (
item(lst, i + lst->
idx) ==
data)
return true;
35 lst_thing const *item1 = one, *item2 = two;
37 return CMP(item1->
data, item2->data);
45 for (i = 0; i < len; i++) {
55 for (i = 0; i < len; i++) {
57 int temp = values[i].
data;
60 values[j].
data = temp;
75 for (
unsigned int i = 0; i <
NUM_ELEMENTS(values); i++) {
80 for (
unsigned int i = 0; i <
NUM_ELEMENTS(values); i++) {
92#define LST_TEST_SIZE (4096)
119 TEST_MSG(
"element %i inserted but not in LST", i);
126 TEST_MSG(
"element %i removed out of order", entry);
129 TEST_MSG(
"element %i removal failed, returned %i", entry, ret);
132 TEST_MSG(
"element %i removed but still in LST", entry);
135 TEST_MSG(
"element %i removed out of order", entry);
139 for (i = 0; i < left; i++) {
145 TEST_MSG(
"expected %i elements remaining in the lst", left - i);
146 TEST_MSG(
"failed extracting %i", i);
150 TEST_MSG(
"%i elements remaining", ret);
250#define BURN_IN_OPS (10000000)
257 int insert_count = 0;
297#define LST_CYCLE_SIZE (1600000)
305 int inserted, removed;
307 fr_time_t start_insert, start_remove, start_swap, end;
334 for (i = 0; i < to_remove; i++) {
339 TEST_MSG(
"failed extracting %i", i);
340 TEST_MSG(
"expected %i elements remaining in the LST", to_remove - i);
352 if (values[i].idx == 0) {
358 TEST_MSG(
"element %i removal failed, returned %i", i, ret);
402 data->visited =
true;
419 unsigned int idx = 0;
421 for (
unsigned int j = 0; j <
count; j++) {
422 if (!array[j])
continue;
424 if (!low || (
lst_cmp(array[j], low) < 0)) {
429 if (low) array[idx] = NULL;
452 fr_time_t start_alloc, end_alloc, start_insert, end_insert, start_pop, end_pop, end_pop_first =
fr_time_wrap(0);
466 for (i = 0; i <
count; i++) {
471 if (i == 0) end_pop_first =
fr_time();
473 TEST_MSG(
"expected %u elements remaining in the lst",
count - i);
474 TEST_MSG(
"failed extracting %u", i);
491 fr_time_t start_alloc, end_alloc, start_insert, end_insert, start_pop, end_pop, end_pop_first =
fr_time_wrap(0);
505 for (i = 0; i <
count; i++) {
510 if (i == 0) end_pop_first =
fr_time();
512 TEST_MSG(
"expected %u elements remaining in the heap",
count - i);
513 TEST_MSG(
"failed extracting %u", i);
531 fr_time_t start_alloc, end_alloc, start_insert, end_insert, start_pop, end_pop, end_pop_first;
541 for (i = 0; i <
count; i++) array[i] = &values[i];
545 for (i = 0; i <
count; i++) {
547 if (i == 0) end_pop_first =
fr_time();
605 unsigned int i, remaining;
607 TEST_CASE(
"comparator error fails closed");
#define TEST_MSG_ALWAYS(...)
#define TEST_ASSERT(cond)
#define CMP(_a, _b)
Same as CMP_PREFER_SMALLER use when you don't really care about ordering, you just want an ordering.
int fr_heap_insert(fr_heap_t **hp, void *data)
Insert a new element into the heap.
int fr_heap_pop(void **out, fr_heap_t **hp)
Remove a node from the heap.
#define fr_heap_alloc(_ctx, _cmp, _type, _field, _init)
Creates a heap that can be used with non-talloced elements.
static unsigned int fr_heap_num_elements(fr_heap_t *h)
Return the number of elements in the heap.
void * fr_lst_iter_next(fr_lst_t *lst, fr_lst_iter_t *iter)
Get the next entry in an LST.
int fr_lst_extract(fr_lst_t *lst, void *data)
Remove an element from an LST.
int fr_lst_pop(void **out, fr_lst_t *lst)
void * fr_lst_iter_init(fr_lst_t *lst, fr_lst_iter_t *iter)
Iterate over entries in LST.
static void * item(fr_lst_t const *lst, fr_lst_index_t idx)
fr_lst_index_t idx
Starting index, initially zero.
int fr_lst_insert(fr_lst_t *lst, void *data)
unsigned int fr_lst_num_elements(fr_lst_t *lst)
int fr_lst_peek(void **out, fr_lst_t *lst)
#define FR_LST_VERIFY(_lst)
#define fr_lst_alloc(_ctx, _cmp, _type, _field, _init)
Creates an LST that can be used with non-talloced elements.
static bool fr_lst_entry_inserted(fr_lst_index_t lst_id)
Check if an entry is inserted into an LST.
fr_lst_index_t fr_lst_iter_t
unsigned int fr_lst_index_t
#define fr_lst_foreach(_lst, _type, _data)
Iterate over the contents of an LST.
static void queue_cmp_100(void)
static void queue_cmp(unsigned int count)
Benchmarks for LSTs vs heaps when used as queues.
static lst_thing * array_pop(lst_thing **array, unsigned int count)
static void lst_test_skip_10(void)
static fr_cmp_ret_t _lst_poison_cmp(void const *one, void const *two)
static void lst_test(int skip)
static fr_cmp_ret_t lst_cmp(void const *one, void const *two)
static void lst_test_cmp_err(void)
static void queue_cmp_50(void)
static void lst_cycle(void)
static void lst_burn_in(void)
static void lst_test_basic(void)
static void lst_iter(void)
static void queue_cmp_1000(void)
static void lst_test_skip_2(void)
static void queue_cmp_10(void)
static bool fr_lst_contains(fr_lst_t *lst, void *data)
static void lst_test_skip_1(void)
static void lst_stress_realloc(void)
static void populate_values(lst_thing values[], unsigned int len)
fr_cmp_ret_t
Result of an ordering comparison.
@ CMP_ERR
comparison failed
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.
static int64_t fr_time_delta_unwrap(fr_time_delta_t time)
#define fr_time_wrap(_time)
#define fr_time_sub(_a, _b)
Subtract one time from another.
char const * fr_strerror(void)
Get the last library error.
#define fr_strerror_const(_msg)