#include "xroad_common_fwd.h"#include "xroad_common_types.h"#include "xroad_aux.h"#include <common/xroad_string.h>#include <stdlib.h>#include <stddef.h>#include <stdalign.h>
Go to the source code of this file.
Classes | |
| struct | xroad_hashmap_va_args_t |
| struct | xroad_hashmap_insert_result_t |
Macros | |
| #define | XROAD_HASHMAP_ENTRY_STRUCT(key_type, value_type) struct { int8_t info; key_type key; value_type value; int8_t last_member; } |
| #define | XROAD_HASHMAP_ENTRY_KEY_OFFSET(key_type, value_type) offsetof(XROAD_HASHMAP_ENTRY_STRUCT(key_type, value_type), key) |
| #define | XROAD_HASHMAP_ENTRY_VALUE_OFFSET(key_type, value_type) offsetof(XROAD_HASHMAP_ENTRY_STRUCT(key_type, value_type), value) |
| #define | XROAD_HASHMAP_ENTRY_SIZE(key_type, value_type) offsetof(XROAD_HASHMAP_ENTRY_STRUCT(key_type, value_type), last_member) |
| #define | xroad_hashmap_create(key_type, value_type, ...) |
| #define | __xroad_hashmap_dtor__ __dtor__(xroad_hashmap_destructor) |
Typedefs | |
| typedef uint32_t(* | xroad_hashmap_hash_func_t) (const void *, uint32_t) |
| typedef int32_t(* | xroad_hashmap_equal_func_t) (const void *, const void *, uint32_t) |
| typedef void(* | xroad_hashmap_free_func_t) (void *) |
Functions | |
| uint32_t | xroad_hashmap_hash_func_cstr (const void *, uint32_t) |
| int32_t | xroad_hashmap_equal_func_cstr (const void *, const void *, uint32_t) |
| void | xroad_hashmap_free_func_cstr (void *) |
| uint32_t | xroad_hashmap_hash_func_xroad_str (const void *, uint32_t) |
| int32_t | xroad_hashmap_equal_func_xroad_str (const void *, const void *, uint32_t) |
| void | xroad_hashmap_free_func_xroad_str (void *) |
| uint32_t | xroad_hashmap_hash_func_uint32 (const void *data, uint32_t size) |
| int32_t | xroad_hashmap_equal_func_uint32 (const void *l, const void *r, uint32_t s) |
| uint32_t | xroad_hashmap_hash_func_uint64 (const void *data, uint32_t size) |
| int32_t | xroad_hashmap_equal_func_uint64 (const void *l, const void *r, uint32_t s) |
| xroad_hashmap_t * | xroad_hashmap_create_ex (uint32_t sizeof_key, uint32_t sizeof_value, uint32_t sizeof_entry, uint32_t key_offset, uint32_t value_offset, uint32_t initiad_size, xroad_hashmap_hash_func_t hash_func, xroad_hashmap_equal_func_t equal_func, xroad_hashmap_free_func_t key_free_func, xroad_hashmap_free_func_t value_free_func, xroad_mem_pool_t *pool) |
| void | xroad_hashmap_destroy (xroad_hashmap_t *hashmap) |
| void | xroad_hashmap_destructor (void *hashmap_ptr) |
| void | xroad_hashmap_reserve (xroad_hashmap_t *hashmap, uint32_t size) |
| xroad_hashmap_insert_result_t | xroad_hashmap_insert (xroad_hashmap_t *hashmap, const void *key, const void *value) |
| xroad_hashmap_entry_t * | xroad_hashmap_find (xroad_hashmap_t *hashmap, const void *key) |
| void | xroad_hashmap_clear (xroad_hashmap_t *hashmap) |
| uint32_t | xroad_hashmap_get_key_size (const xroad_hashmap_t *hashmap) |
| uint32_t | xroad_hashmap_get_value_size (const xroad_hashmap_t *hashmap) |
| xroad_errno_t | xroad_hashmap_delete (xroad_hashmap_t *hashmap, const void *key, bool free_resources) |
| uint32_t | xroad_hashmap_get_size (xroad_hashmap_t *hashmap) |
| xroad_list_t * | xroad_hashmap_keys_to_list (xroad_hashmap_t *hashmap) |
| xroad_list_t * | xroad_hashmap_values_to_list (xroad_hashmap_t *hashmap) |
| void * | xroad_hashmap_entry_get_key (xroad_hashmap_t *hashmap, xroad_hashmap_entry_t *entry) |
| void * | xroad_hashmap_entry_get_value (xroad_hashmap_t *hashmap, xroad_hashmap_entry_t *entry) |
| void | xroad_hashmap_entry_set_value (xroad_hashmap_t *hashmap, xroad_hashmap_entry_t *entry, const void *value, bool free_resources) |
| void | xroad_hashmap_entry_delete (xroad_hashmap_t *hashmap, xroad_hashmap_entry_t *entry, bool free_resources) |
| xroad_hashmap_entry_t * | xroad_hashmap_entry_delete_and_get_next (xroad_hashmap_t *hashmap, xroad_hashmap_entry_t *entry, bool free_resources) |
| xroad_hashmap_entry_t * | xroad_hashmap_get_first (xroad_hashmap_t *hashmap) |
| xroad_hashmap_entry_t * | xroad_hashmap_entry_get_next (xroad_hashmap_t *hashmap, xroad_hashmap_entry_t *entry) |
| int32_t | xroad_xstr_eq (const void *first_key, const void *second_key, uint32_t size) |
| #define xroad_hashmap_create | ( | key_type, | |
| value_type, | |||
| ... | |||
| ) |
| #define XROAD_HASHMAP_ENTRY_STRUCT | ( | key_type, | |
| value_type | |||
| ) | struct { int8_t info; key_type key; value_type value; int8_t last_member; } |
sizeof(struct { ... }) isn't valid expression in C++, so we use offsetof(struct { ... }, last_member) instead as a workaround
| typedef int32_t(* xroad_hashmap_equal_func_t) (const void *, const void *, uint32_t) |
equal function type
| typedef void(* xroad_hashmap_free_func_t) (void *) |
free function type
| typedef uint32_t(* xroad_hashmap_hash_func_t) (const void *, uint32_t) |
hash function type
| void xroad_hashmap_clear | ( | xroad_hashmap_t * | hashmap | ) |
delete all entries from hash table
| [in] | hashmap | - instance of hashmap |
| xroad_hashmap_t* xroad_hashmap_create_ex | ( | uint32_t | sizeof_key, |
| uint32_t | sizeof_value, | ||
| uint32_t | sizeof_entry, | ||
| uint32_t | key_offset, | ||
| uint32_t | value_offset, | ||
| uint32_t | initiad_size, | ||
| xroad_hashmap_hash_func_t | hash_func, | ||
| xroad_hashmap_equal_func_t | equal_func, | ||
| xroad_hashmap_free_func_t | key_free_func, | ||
| xroad_hashmap_free_func_t | value_free_func, | ||
| xroad_mem_pool_t * | pool | ||
| ) |
create new hashmap
| [in] | sizeof_key | - sizeof key |
| [in] | sizeof_value | - sizeof value |
| [in] | key_offet | - alignof key |
| [in] | value_offset | - alignof value |
| [in] | initiad_size | - initial size of hashmap. Can be 0 |
| [in] | max_load_factor | - max load factor. Can be 0, so max load factor = 0.5 will be used |
| [in] | hash_func | - hash function, if NULL - default function is used |
| [in] | equal_func | - equality function, used for entry search. if NULL - default function is used |
| [in] | key_free_func | - key destructor function. if NULL - no free function will be used |
| [in] | value_free_func | - value destructor function. if NULL - no free function will be used |
| [in] | pool | - memory pool if any. Can be NULL, so libc malloc/calloc will be used |
| xroad_errno_t xroad_hashmap_delete | ( | xroad_hashmap_t * | hashmap, |
| const void * | key, | ||
| bool | free_resources | ||
| ) |
delete entry from hashmap
| [in] | hashmap | - instance of hashmap |
| [in] | key | - key to delete |
| [in] | free_resources | - if true free all allocated resources using key_dtor and value_dtor from hashmap constructor |
| void xroad_hashmap_destroy | ( | xroad_hashmap_t * | hashmap | ) |
delete hashmap and free all resources
| [in] | hashmap | - hash table to delete. If hash is NULL, nothing happened |
| void xroad_hashmap_entry_delete | ( | xroad_hashmap_t * | hashmap, |
| xroad_hashmap_entry_t * | entry, | ||
| bool | free_resources | ||
| ) |
delete entry
| [in] | hashmap | - instance of hashmap |
| [in] | entry | - entry to delete |
| [in] | free_resources | - if true free all allocated resources using key_dtor and value_dtor from hashmap constructor |
| xroad_hashmap_entry_t* xroad_hashmap_entry_delete_and_get_next | ( | xroad_hashmap_t * | hashmap, |
| xroad_hashmap_entry_t * | entry, | ||
| bool | free_resources | ||
| ) |
delete entry and return next entry, NULL if there are no more
| [in] | hashmap | - instance of hashmap |
| [in] | entry | - entry to delete |
| [in] | free_resources | - if true free all allocated resources using key_dtor and value_dtor from hashmap constructor |
| void* xroad_hashmap_entry_get_key | ( | xroad_hashmap_t * | hashmap, |
| xroad_hashmap_entry_t * | entry | ||
| ) |
return entry key
| [in] | hashmap | - instance of hashmap |
| [in] | entry | - entry to explore |
| xroad_hashmap_entry_t* xroad_hashmap_entry_get_next | ( | xroad_hashmap_t * | hashmap, |
| xroad_hashmap_entry_t * | entry | ||
| ) |
return next entry from hashmap
| [in] | entry | - entry |
| void* xroad_hashmap_entry_get_value | ( | xroad_hashmap_t * | hashmap, |
| xroad_hashmap_entry_t * | entry | ||
| ) |
return entry value
| [in] | hashmap | - instance of hashmap |
| [in] | entry | - entry to explore |
| void xroad_hashmap_entry_set_value | ( | xroad_hashmap_t * | hashmap, |
| xroad_hashmap_entry_t * | entry, | ||
| const void * | value, | ||
| bool | free_resources | ||
| ) |
set entry value
| [in] | hashmap | - instance of hashmap |
| [in] | entry | - entry to set |
| [in] | value | - new value to set |
| [in] | free_resources | - if true free previously allocated resources using key_dtor and value_dtor from hashmap constructor |
| xroad_hashmap_entry_t* xroad_hashmap_find | ( | xroad_hashmap_t * | hashmap, |
| const void * | key | ||
| ) |
find entry in hash table
| [in] | hashmap | - instance of hashmap |
| [in] | key | - key to find |
| xroad_hashmap_entry_t* xroad_hashmap_get_first | ( | xroad_hashmap_t * | hashmap | ) |
return first entry from hashmap
| [in] | hashmap | - instance of hashmap |
| uint32_t xroad_hashmap_get_key_size | ( | const xroad_hashmap_t * | hashmap | ) |
return entry key size
| [in] | hashmap | - instance of hashmap |
| uint32_t xroad_hashmap_get_size | ( | xroad_hashmap_t * | hashmap | ) |
return number of entries in hashmap
| [in] | hashmap | - instance of hashmap |
| uint32_t xroad_hashmap_get_value_size | ( | const xroad_hashmap_t * | hashmap | ) |
return entry value size
| [in] | hashmap | - instance of hashmap |
| uint32_t xroad_hashmap_hash_func_cstr | ( | const void * | , |
| uint32_t | |||
| ) |
default hashmap functions for cstr: -> xroad_hashmap_hash_func_cstr hashes strlen() bytes -> xroad_hashmap_equal_func_cstr use strcmp for compare -> xroad_hashmap_free_func_cstr use free() to free allocated memory
|
inline |
Useful hashmap functions for int32 and int64
| uint32_t xroad_hashmap_hash_func_xroad_str | ( | const void * | , |
| uint32_t | |||
| ) |
default hashmap functions for xroad_str: -> xroad_hashmap_hash_func_xroad_str hashes str.len bytes -> xroad_hashmap_equal_func_xroad_str use xroad_str_cmp for compare -> xroad_hashmap_free_func_xroad_str use free() to free allocated memory
| xroad_hashmap_insert_result_t xroad_hashmap_insert | ( | xroad_hashmap_t * | hashmap, |
| const void * | key, | ||
| const void * | value | ||
| ) |
insert new entry into hashmap
| [in] | hashmap | - instance of hashmap |
| [in] | key | - pointer to key data |
| [in] | value | - pointer to value data |
| xroad_list_t* xroad_hashmap_keys_to_list | ( | xroad_hashmap_t * | hashmap | ) |
convert hashmap keys to list
| [in] | hashmap | - instance of hashmap to convert |
| void xroad_hashmap_reserve | ( | xroad_hashmap_t * | hashmap, |
| uint32_t | size | ||
| ) |
reserve space for size items
| [in] | hashmap | - instance of hashmap |
| [in] | size | - size |
| xroad_list_t* xroad_hashmap_values_to_list | ( | xroad_hashmap_t * | hashmap | ) |
convert hashmap values to list
| [in] | hashmap | - instance of hashmap to convert |