|
CNDP
22.08.0
|
#include <stdbool.h>#include <string.h>#include <strings.h>#include <stdint.h>#include <stdio.h>#include <sys/queue.h>#include <pthread.h>#include "cne_common.h"#include "cne_log.h"Go to the source code of this file.
Data Structures | |
| struct | hmap_kvp |
| struct | hmap |
Macros | |
| #define | HMAP_MAX_NAME_SIZE 32 |
| #define | HMAP_MAX_KEY_SIZE 256 |
| #define | HMAP_STARTING_CAPACITY 32 |
| #define | HMAP_DEFAULT_CAPACITY 1024 |
Typedefs | |
| typedef struct hmap_kvp | hmap_kvp_t |
| typedef struct hmap | hmap_t |
Functions | |
| CNDP_API hmap_t * | hmap_create (const char *name, uint32_t capacity, hmap_funcs_t *funcs) |
| CNDP_API int | hmap_destroy (hmap_t *hmap) |
| CNDP_API int | hmap_destroy_by_name (const char *name) |
| CNDP_API hmap_kvp_t * | hmap_kvp_lookup (hmap_t *hmap, const char *prefix, const char *key) |
| CNDP_API int | hmap_lookup (hmap_t *hmap, const char *prefix, const char *key, hmap_val_t *val) |
| 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_kvp_update (hmap_t *hmap, hmap_kvp_t *kvp, hmap_val_t *val) |
| static int | hmap_add_string (hmap_t *hmap, const char *prefix, const char *key, const char *val) |
| CNDP_API int | hmap_del (hmap_t *hmap, const char *prefix, const char *key) |
| CNDP_API int | hmap_iterate (hmap_t *hmap, hmap_kvp_t **_kvp, uint32_t *next) |
| CNDP_API void | hmap_dump (FILE *f, hmap_t *hmap, int sort) |
| static uint32_t | hmap_capacity (hmap_t *hmap) |
| static uint32_t | hmap_count (hmap_t *hmap) |
| CNDP_API hmap_funcs_t * | hmap_get_funcs (hmap_t *hmap) |
| CNDP_API int | hmap_set_funcs (hmap_t *hmap, hmap_funcs_t *funcs) |
| static hmap_kvp_t * | __get_kvp (hmap_t *hmap, const char *prefix, const char *key, hmap_type_t type) |
| static int | hmap_get_bool (hmap_t *hmap, const char *prefix, const char *key, bool *val) |
| static int | hmap_get_u64 (hmap_t *hmap, const char *prefix, const char *key, uint64_t *val) |
| static int | hmap_get_u32 (hmap_t *hmap, const char *prefix, const char *key, uint32_t *val) |
| static int | hmap_get_u16 (hmap_t *hmap, const char *prefix, const char *key, uint16_t *val) |
| 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) |
| static int | hmap_get_num64 (hmap_t *hmap, const char *prefix, const char *key, int64_t *val) |
| static int | hmap_get_string (hmap_t *hmap, const char *prefix, const char *key, char **val) |
| static int | hmap_get_pointer (hmap_t *hmap, const char *prefix, const char *key, void **val) |
| void | hmap_list_dump (FILE *f, int sort) |
This library provides an API for the hashmap data structure
Definition in file hmap.h.
| #define HMAP_STARTING_CAPACITY 32 |
| #define HMAP_DEFAULT_CAPACITY 1024 |
| typedef struct hmap_kvp hmap_kvp_t |
A structure used to retrieve information of a key-value-pair hmap
| CNDP_API hmap_t* hmap_create | ( | const char * | name, |
| uint32_t | capacity, | ||
| hmap_funcs_t * | funcs | ||
| ) |
Create a hashmap structure with a fixed capacity hash size
| name | A string name for this hashmap |
| capacity | The size of the hash table |
| funcs | Optional pointer to hmap_funcs_t structure to allow user to set hmap functions. |
| CNDP_API int hmap_destroy | ( | hmap_t * | hmap | ) |
Destroy a hashmap table
| hmap | Pointer to the hmap structure |
| CNDP_API int hmap_destroy_by_name | ( | const char * | name | ) |
Destroy the hmap using its name
| name | The name of the hmap |
| CNDP_API hmap_kvp_t* hmap_kvp_lookup | ( | hmap_t * | hmap, |
| const char * | prefix, | ||
| const char * | key | ||
| ) |
Lookup a prefix/key value in the hashmap
| hmap | Pointer to the hmap structure |
| prefix | The prefix string |
| key | The key to search for in the hashmap |
| CNDP_API int hmap_lookup | ( | hmap_t * | hmap, |
| const char * | prefix, | ||
| const char * | key, | ||
| hmap_val_t * | val | ||
| ) |
Lookup a prefix/key value in the hashmap
| hmap | Pointer to the hmap structure |
| prefix | The prefix string |
| key | The key to search for in the hashmap |
| val | Pointer to hmap_val_t to return value can be NULL for no return value |
| CNDP_API int hmap_add | ( | hmap_t * | hmap, |
| hmap_type_t | type, | ||
| const char * | prefix, | ||
| const char * | key, | ||
| hmap_val_t * | val | ||
| ) |
Add a key/value pair the hashmap table
| hmap | Pointer to the hmap structure |
| type | The hmap_type_t type for the value pointer |
| prefix | The prefix string to locate in the hashmap table |
| key | The key value string to add |
| val | The value pointer to store with the key/value entry. |
| CNDP_API int hmap_kvp_update | ( | hmap_t * | hmap, |
| hmap_kvp_t * | kvp, | ||
| hmap_val_t * | val | ||
| ) |
Update the value for the given key/value pair return by hmap_kvp_lookup().
| hmap | Pointer to hmap structure |
| kvp | The key/value pair structure to update |
| val | The pointer to the new value. |
|
inlinestatic |
Add a key/value pair the hashmap table for all of the types allowed.
| hmap | Pointer to the hmap structure |
| prefix | The prefix string to locate in the hashmap table |
| key | The key value string to add |
| val | The value to be stored in the hmap table. |
| CNDP_API int hmap_del | ( | hmap_t * | hmap, |
| const char * | prefix, | ||
| const char * | key | ||
| ) |
Delete a hashmap entry
| hmap | Pointer to the hmap structure |
| prefix | The prefix string for the hashmap |
| key | The Key to search for in the table |
| CNDP_API int hmap_iterate | ( | hmap_t * | hmap, |
| hmap_kvp_t ** | _kvp, | ||
| uint32_t * | next | ||
| ) |
Iterate over the all of the entries in the hashmap
| hmap | Pointer to the hmap structure |
| _kvp | The address to place the key/value pair structure pointer |
| next | The next entry to iterate as an index value. |
| CNDP_API void hmap_dump | ( | FILE * | f, |
| hmap_t * | hmap, | ||
| int | sort | ||
| ) |
Dump out all of the entries in a hashmap
| f | The file descriptor to use for output of the text |
| hmap | Pointer to the hmap structure to dump |
| sort | The sort flag is non-zero then sort the output |
|
inlinestatic |
|
inlinestatic |
| CNDP_API hmap_funcs_t* hmap_get_funcs | ( | hmap_t * | hmap | ) |
Get the set of hmap function pointers.
| hmap | The hmap structure pointer |
| CNDP_API int hmap_set_funcs | ( | hmap_t * | hmap, |
| hmap_funcs_t * | funcs | ||
| ) |
Set the hashing function
| hmap | Pointer to the hmap structure |
| funcs | Pointer to a set of function pointers |
|
inlinestatic |
Get a key/value pair from the hmap if is exists. (internal)
| hmap | Pointer to the hmap structure |
| prefix | The prefix string pointer, can be NULL if a global value |
| key | The key value string to get the boolean value. |
| type | The key value type. |
|
inlinestatic |
Get a boolean value from the hmap.
| hmap | Pointer to the hmap structure |
| prefix | The prefix string pointer, can be NULL if a global value |
| key | The key value string to get the boolean value. |
| val | The location to store the value. |
|
inlinestatic |
Get a uint64_t value from the hmap.
| hmap | Pointer to the hmap structure |
| prefix | The prefix string pointer, can be NULL if a global value |
| key | The key value string to get the uint64_t value. |
| val | The location to store the value. |
|
inlinestatic |
Get a uint32_t value from the hmap.
| hmap | Pointer to the hmap structure |
| prefix | The prefix string pointer, can be NULL if a global value |
| key | The key value string to get the uint32_t value. |
| val | The location to store the value. |
|
inlinestatic |
Get a uint16_t value from the hmap.
| hmap | Pointer to the hmap structure |
| prefix | The prefix string pointer, can be NULL if a global value |
| key | The key value string to get the uint16_t value. |
| val | The location to store the value. |
|
inlinestatic |
Get a uint8_t value from the hmap.
| hmap | Pointer to the hmap structure |
| prefix | The prefix string pointer, can be NULL if a global value |
| key | The key value string to get the uint8_t value. |
| val | The location to store the value. |
|
inlinestatic |
Get a number value from the hmap.
| hmap | Pointer to the hmap structure |
| prefix | The prefix string pointer, can be NULL if a global value |
| key | The key value string to get the number value. |
| val | The location to store the value. |
|
inlinestatic |
Get a number value from the hmap as a int64_t.
| hmap | Pointer to the hmap structure |
| prefix | The prefix string pointer, can be NULL if a global value |
| key | The key value string to get the number value. |
| val | The location to store the value. |
|
inlinestatic |
Get a string value from the hmap.
| hmap | Pointer to the hmap structure |
| prefix | The prefix string pointer, can be NULL if a global value |
| key | The key value string to get the string value. |
| val | A pointer to the return value or NULL if no return value is needed. |
|
inlinestatic |
Get a pointer value from the hmap.
| hmap | Pointer to the hmap structure |
| prefix | The prefix string pointer, can be NULL if a global value |
| key | The key value string to get the string value. |
| val | A pointer to the return value or NULL if no return value is needed. |
| void hmap_list_dump | ( | FILE * | f, |
| int | sort | ||
| ) |
Dump all of the hmap lists
| f | The file descriptor to dump the text data. |
| sort | if not zero then sort the output |