2025-01-28 21:42:26 +00:00
|
|
|
#ifndef _H_MCU_COLLECT_HASH_MAP
|
|
|
|
#define _H_MCU_COLLECT_HASH_MAP
|
|
|
|
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdlib.h>
|
2025-01-29 21:21:18 +00:00
|
|
|
#include "mcutil/mcutil.h"
|
2025-01-28 21:42:26 +00:00
|
|
|
|
2025-02-04 13:03:27 +00:00
|
|
|
typedef struct mcu_gen_hm_node_s {
|
2025-01-28 21:42:26 +00:00
|
|
|
uint8_t key[16];
|
|
|
|
void* value;
|
2025-02-04 13:03:27 +00:00
|
|
|
struct mcu_gen_hm_node_s* next;
|
|
|
|
} mcu_gen_hm_node_t;
|
2025-01-28 21:42:26 +00:00
|
|
|
|
2025-02-04 13:03:27 +00:00
|
|
|
typedef struct mcu_gen_hm_s {
|
|
|
|
mcu_gen_hm_node_t* nodes;
|
|
|
|
} mcu_gen_hm_t;
|
2025-01-28 21:42:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
#define mcu_hm_insert(hm, key, value) _mcu_hm_insert((hm), (key), (const size_t)sizeof(key), (value));
|
|
|
|
#define mcu_hm_get(hm, key) _mcu_hm_insert((hm), (key), (const size_t)sizeof(key));
|
|
|
|
#define mcu_hm_remove(hm, key) _mcu_hm_insert((hm), (key), (const size_t)sizeof(key));
|
|
|
|
|
2025-02-04 13:03:27 +00:00
|
|
|
MCU_API mcu_gen_hm_t mcu_hm_new();
|
|
|
|
MCU_API void _mcu_hm_insert(mcu_gen_hm_t* hm, const void* key, const size_t key_len, const void* value);
|
|
|
|
MCU_API void* _mcu_hm_get (mcu_gen_hm_t* hm, const void* key, const size_t key_len);
|
|
|
|
MCU_API void* _mcu_hm_remove(mcu_gen_hm_t* hm, const void* key, const size_t key_len);
|
2025-01-28 21:42:26 +00:00
|
|
|
/// Frees the hashmap but not the pointers inside the values
|
2025-02-04 13:03:27 +00:00
|
|
|
MCU_API void mcu_free(mcu_gen_hm_t* hm);
|
2025-01-28 21:42:26 +00:00
|
|
|
/// Frees the hashmap and the pointers inside the values
|
2025-02-04 13:03:27 +00:00
|
|
|
MCU_API void mcu_free_all(mcu_gen_hm_t* hm);
|
2025-01-28 21:42:26 +00:00
|
|
|
|
|
|
|
#endif // _H_MCU_COLLECT_HASH_MAP
|