mccu/include/mcutil/collect/gen_hash_map.h
2025-02-04 15:03:27 +02:00

34 lines
1.2 KiB
C

#ifndef _H_MCU_COLLECT_HASH_MAP
#define _H_MCU_COLLECT_HASH_MAP
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include "mcutil/mcutil.h"
typedef struct mcu_gen_hm_node_s {
uint8_t key[16];
void* value;
struct mcu_gen_hm_node_s* next;
} mcu_gen_hm_node_t;
typedef struct mcu_gen_hm_s {
mcu_gen_hm_node_t* nodes;
} mcu_gen_hm_t;
#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));
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);
/// Frees the hashmap but not the pointers inside the values
MCU_API void mcu_free(mcu_gen_hm_t* hm);
/// Frees the hashmap and the pointers inside the values
MCU_API void mcu_free_all(mcu_gen_hm_t* hm);
#endif // _H_MCU_COLLECT_HASH_MAP