21 #include <sys/queue.h>
31 #define HMAP_MAX_NAME_SIZE 32
32 #define HMAP_MAX_KEY_SIZE 256
33 #define HMAP_STARTING_CAPACITY 32
34 #define HMAP_DEFAULT_CAPACITY 1024
76 typedef uint32_t (*hash_fn_t)(
const char *prefix,
const char *key);
77 typedef int (*cmp_fn_t)(
const char *prefix,
const char *key,
const hmap_kvp_t *kvp);
80 typedef struct hmap_funcs {
214 hmap_val_t v = {.str = (
char *)(uintptr_t)val};
220 hmap_add_u64(
hmap_t *
hmap,
const char *prefix,
const char *key, uint64_t val)
222 hmap_val_t v = {.u64 = val};
228 hmap_add_u32(
hmap_t *
hmap,
const char *prefix,
const char *key, uint32_t val)
230 hmap_val_t v = {.u32 = val};
236 hmap_add_u16(
hmap_t *
hmap,
const char *prefix,
const char *key, uint16_t val)
238 hmap_val_t v = {.u16 = val};
244 hmap_add_u8(
hmap_t *
hmap,
const char *prefix,
const char *key, uint8_t val)
246 hmap_val_t v = {.u8 = val};
252 hmap_add_num(
hmap_t *
hmap,
const char *prefix,
const char *key,
int val)
254 hmap_val_t v = {.num = val};
260 hmap_add_num64(
hmap_t *
hmap,
const char *prefix,
const char *key, int64_t val)
262 hmap_val_t v = {.num64 = val};
264 return hmap_add(
hmap, HMAP_NUM64_TYPE, prefix, key, &v);
268 hmap_add_bool(
hmap_t *
hmap,
const char *prefix,
const char *key,
bool val)
270 hmap_val_t v = {.boolean = val};
272 return hmap_add(
hmap, HMAP_BOOLEAN_TYPE, prefix, key, &v);
276 hmap_add_pointer(
hmap_t *
hmap,
const char *prefix,
const char *key,
void *val)
278 hmap_val_t v = {.ptr = val};
280 return hmap_add(
hmap, HMAP_POINTER_TYPE, prefix, key, &v);
331 static inline uint32_t
345 static inline uint32_t
393 CNE_NULL_RET(
"get failed - hmap not defined %s(%s)\n", prefix ? prefix :
"", key);
396 if (!kvp || kvp->
type != type)
397 CNE_NULL_RET(
"get failed for %s(%s)\n", prefix ? prefix :
"", key);
421 if (!kvp || kvp->
type != HMAP_BOOLEAN_TYPE)
425 *val = kvp->
v.boolean;
449 if (!kvp || kvp->
type != HMAP_U64_TYPE)
477 if (!kvp || kvp->
type != HMAP_U32_TYPE)
505 if (!kvp || kvp->
type != HMAP_U16_TYPE)
533 if (!kvp || kvp->
type != HMAP_U8_TYPE)
561 if (!kvp || kvp->
type != HMAP_NUM_TYPE)
589 if (!kvp || kvp->
type != HMAP_NUM64_TYPE)
617 if (!kvp || kvp->
type != HMAP_STR_TYPE)
645 if (!kvp || kvp->
type != HMAP_POINTER_TYPE)
#define CNE_NULL_RET(...)
static int hmap_get_bool(hmap_t *hmap, const char *prefix, const char *key, bool *val)
CNDP_API void hmap_dump(FILE *f, hmap_t *hmap, int sort)
CNDP_API int hmap_del(hmap_t *hmap, const char *prefix, const char *key)
void hmap_list_dump(FILE *f, int sort)
static int hmap_get_pointer(hmap_t *hmap, const char *prefix, const char *key, void **val)
CNDP_API hmap_funcs_t * hmap_get_funcs(hmap_t *hmap)
CNDP_API hmap_kvp_t * hmap_kvp_lookup(hmap_t *hmap, const char *prefix, const char *key)
struct hmap_kvp hmap_kvp_t
CNDP_API int hmap_destroy(hmap_t *hmap)
CNDP_API int hmap_add(hmap_t *hmap, hmap_type_t type, const char *prefix, const char *key, hmap_val_t *val)
CNDP_API int hmap_set_funcs(hmap_t *hmap, hmap_funcs_t *funcs)
static uint32_t hmap_count(hmap_t *hmap)
CNDP_API int hmap_destroy_by_name(const char *name)
static int hmap_get_string(hmap_t *hmap, const char *prefix, const char *key, char **val)
static int hmap_get_num64(hmap_t *hmap, const char *prefix, const char *key, int64_t *val)
#define HMAP_MAX_NAME_SIZE
static uint32_t hmap_capacity(hmap_t *hmap)
CNDP_API int hmap_iterate(hmap_t *hmap, hmap_kvp_t **_kvp, uint32_t *next)
CNDP_API int hmap_lookup(hmap_t *hmap, const char *prefix, const char *key, hmap_val_t *val)
static int hmap_get_u32(hmap_t *hmap, const char *prefix, const char *key, uint32_t *val)
static int hmap_add_string(hmap_t *hmap, const char *prefix, const char *key, const char *val)
static int hmap_get_u16(hmap_t *hmap, const char *prefix, const char *key, uint16_t *val)
static hmap_kvp_t * __get_kvp(hmap_t *hmap, const char *prefix, const char *key, hmap_type_t type)
CNDP_API int hmap_kvp_update(hmap_t *hmap, hmap_kvp_t *kvp, hmap_val_t *val)
static int hmap_get_u64(hmap_t *hmap, const char *prefix, const char *key, uint64_t *val)
CNDP_API hmap_t * hmap_create(const char *name, uint32_t capacity, hmap_funcs_t *funcs)
static int hmap_get_u8(hmap_t *hmap, const char *prefix, const char *key, uint8_t *val)
static int hmap_get_num(hmap_t *hmap, const char *prefix, const char *key, int *val)
char name[HMAP_MAX_NAME_SIZE]