26#include <freeradius-devel/util/hash.h>
27#include <freeradius-devel/util/rand.h>
45 return CMP(a->
num, b->num);
55 TEST_CASE(
"fr_hash produces consistent results");
60 TEST_CASE(
"Different inputs produce different hashes");
72 TEST_CASE(
"fr_hash_case_string is case insensitive");
80 TEST_CASE(
"fr_hash_update for incremental hashing");
94 TEST_CASE(
"fr_hash64 produces consistent results");
99 TEST_CASE(
"Different inputs produce different 64-bit hashes");
103 TEST_CASE(
"fr_hash64_update for incremental hashing");
138 TEST_CASE(
"Find non-existent element returns NULL");
145#define HASH_TEST_SIZE 1024
193 TEST_CASE(
"Verify removed elements are gone and remaining are present");
200 TEST_MSG(
"element %d should have been removed", i);
203 TEST_MSG(
"element %d should still be present", i);
253 TEST_CASE(
"Replace on empty table inserts");
265 TEST_CASE(
"Find returns the replacement");
289 TEST_CASE(
"Delete removes and frees element");
293 TEST_CASE(
"Delete non-existent element returns false");
311 unsigned int count = 0;
318 for (i = 0; i < 16; i++) {
330 seen |= (1U << p->
num);
353 for (i = 0; i < 8; i++) {
366 for (i = 0; i < 8; i++) {
370 seen |= (1U << flat[i]->
num);
#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.
void * fr_hash_table_iter_next(fr_hash_table_t *ht, fr_hash_iter_t *iter)
Iterate over entries in a hash table.
void * fr_hash_table_find(fr_hash_table_t *ht, void const *data)
Find data in a hash table.
void * fr_hash_table_iter_init(fr_hash_table_t *ht, fr_hash_iter_t *iter)
Initialise an iterator.
uint32_t fr_hash_case_string(char const *p)
Hash a C string, converting all chars to lowercase.
uint32_t fr_hash_update(void const *data, size_t size, uint32_t hash)
uint32_t fr_hash(void const *data, size_t size)
uint64_t fr_hash64(void const *data, size_t size)
bool fr_hash_table_insert(fr_hash_table_t *ht, void const *data)
Insert data into a hash table.
void * fr_hash_table_remove(fr_hash_table_t *ht, void const *data)
Remove an entry from the hash table, without freeing the data.
int fr_hash_table_flatten(TALLOC_CTX *ctx, void **out[], fr_hash_table_t *ht)
Copy all entries out of a hash table into an array.
uint32_t fr_hash_string(char const *p)
bool fr_hash_table_delete(fr_hash_table_t *ht, void const *data)
Remove and free data (if a free function was specified)
uint64_t fr_hash64_update(void const *data, size_t size, uint64_t hash)
int fr_hash_table_replace(void **old, fr_hash_table_t *ht, void const *data)
Replace old data with new data, OR insert if there is no old.
uint32_t fr_hash_table_num_elements(fr_hash_table_t *ht)
#define fr_hash_table_alloc(_ctx, _hash_node, _cmp_node, _free_node)
Stores the state of the current iteration operation.
static void test_hash_table_iter(void)
static void test_hash_functions(void)
static void test_hash_table_replace(void)
static int8_t hash_test_cmp(void const *one, void const *two)
static void test_hash_table_duplicate(void)
static void test_hash_table_basic(void)
static void test_hash_table_delete(void)
static uint32_t hash_test_hash(void const *data)
static void test_hash_table_many(void)
static void test_hash64_functions(void)
static void test_hash_table_flatten(void)
PUBLIC int snprintf(char *string, size_t length, char *format, va_alist)
void talloc_free_data(void *data)
A wrapper that can be passed to tree or hash alloc functions that take a fr_free_t.