Hash table implementation in C.
More...
|
| #define | c_map_init(m, nreserved) (((m) != NULL) ? _map_init(&(m)->base, (nreserved)) : c_Utility_ErrorCode_Map) |
| |
| #define | c_map_init_default(m) c_map_init((m), 0) |
| |
| #define | c_map_deinit(m) do { if ((m) != NULL) _map_deinit(&(m)->base); } while (0) |
| |
| #define | c_map_get(m, key) (((m) != NULL) ? (m)->ref = _map_get(&(m)->base, (key)) : NULL) |
| |
| #define | c_map_set(m, key, value) (((m) != NULL) ? ((m)->tmp = (value), _map_set(&(m)->base, (key), &(m)->tmp, sizeof((m)->tmp))) : c_Utility_ErrorCode_Map) |
| |
| #define | c_map_remove(m, key) do { if ((m) != NULL) _map_remove(&(m)->base, (key)); } while (0) |
| |
| #define | c_map_size(m) (((m) != NULL) ? _map_size(&(m)->base) : 0) |
| |
| #define | c_map_iter() _map_iter() |
| |
| #define | c_map_next(m, iter) (((m) != NULL) ? _map_next(&(m)->base, (iter)) : NULL) |
| |
| #define | c_map_t(T) struct { c_map_base_t base; T *ref; T tmp; } |
| |
Hash table implementation in C.
- Author
- rxi
- Date
- 2014
- Copyright
- MIT license
◆ c_map_init
Initialize a new map with pre-allocation.
- Parameters
-
| [in] | m | a pointer to an allocated map |
| [in] | nreserved | an integer with the number of buckets to be pre-allocated. If is not a power of 2 or 0, no pre-allocation is done. It is not necessary. It can improve the speed but, on the other hand, could allocate useless space. |
- Returns
- c_Utility_ErrorCode_Success (0) in case of success. Error codes specified in c_Utility_ErrorCode_t.
Definition at line 51 of file CAENMap.h.
◆ c_map_init_default
| #define c_map_init_default |
( |
|
m | ) |
c_map_init((m), 0) |
◆ c_map_deinit
| #define c_map_deinit |
( |
|
m | ) |
do { if ((m) != NULL) _map_deinit(&(m)->base); } while (0) |
Deinitialize a map already initialized by c_map_init().
- Parameters
-
| [in] | m | a pointer to an initialized map |
Definition at line 66 of file CAENMap.h.
◆ c_map_get
| #define c_map_get |
( |
|
m, |
|
|
|
key |
|
) |
| (((m) != NULL) ? (m)->ref = _map_get(&(m)->base, (key)) : NULL) |
Get an element from map given its key
- Parameters
-
| [in] | m | a pointer to an initialized map |
| [in] | key | a string with the key |
- Returns
- a pointer to the element. NULL in case of error.
Definition at line 75 of file CAENMap.h.
◆ c_map_set
| #define c_map_set |
( |
|
m, |
|
|
|
key, |
|
|
|
value |
|
) |
| (((m) != NULL) ? ((m)->tmp = (value), _map_set(&(m)->base, (key), &(m)->tmp, sizeof((m)->tmp))) : c_Utility_ErrorCode_Map) |
◆ c_map_remove
| #define c_map_remove |
( |
|
m, |
|
|
|
key |
|
) |
| do { if ((m) != NULL) _map_remove(&(m)->base, (key)); } while (0) |
Remove an element from map given its key
- Parameters
-
| [in] | m | a pointer to an initialized map |
| [in] | key | a string with the key |
Definition at line 93 of file CAENMap.h.
◆ c_map_size
| #define c_map_size |
( |
|
m | ) |
(((m) != NULL) ? _map_size(&(m)->base) : 0) |
Get the number of elements in a map
- Parameters
-
| [in] | m | a pointer to an initialized map |
- Returns
- the number of nodes
Definition at line 101 of file CAENMap.h.
◆ c_map_iter
Define a new iterator
- Returns
- an interator
Definition at line 108 of file CAENMap.h.
◆ c_map_next
| #define c_map_next |
( |
|
m, |
|
|
|
iter |
|
) |
| (((m) != NULL) ? _map_next(&(m)->base, (iter)) : NULL) |
Get the next key of a map, given an iterator.
- Parameters
-
| [in] | m | a pointer to an initialized map |
| [in,out] | iter | a pointer to an iterator initialized by c_map_iter() |
- Returns
- the next key
Definition at line 117 of file CAENMap.h.
◆ c_map_t
| #define c_map_t |
( |
|
T | ) |
struct { c_map_base_t base; T *ref; T tmp; } |
Define a new map type. To be used like: typedef c_map_t(uint32_t) my_uint32map_t;
- Parameters
-
| [in] | T | the type of the element to be stored |
Definition at line 69 of file CAENMapTypes.h.