From 9500e54b874794bd1d9fb5702aa423c6f1794f27 Mon Sep 17 00:00:00 2001 From: Carson Fleming Date: Sun, 1 Feb 2026 03:23:32 -0500 Subject: add map library --- map.h | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 map.h (limited to 'map.h') diff --git a/map.h b/map.h new file mode 100644 index 0000000..19c8df5 --- /dev/null +++ b/map.h @@ -0,0 +1,44 @@ +#ifndef __SAFEC_MAP_H +#include "types.h" + +typedef size_t (*hash_func_t)(const void*); +typedef bool (*eq_func_t)(const void*, const void*); + +struct __map_entry { + void* key; + void* value; + struct __map_entry* next; +}; + +typedef struct { + hash_func_t hash_func; + eq_func_t eq_func; + double load_limit; + + size_t size; + + size_t __num_buckets; + struct __map_entry* __buckets; +} map_t; + +void map_init( + map_t* map, + hash_func_t hash_func, + eq_func_t eq_func, + double load_limit); +void map_init_capacity( + map_t* map, + hash_func_t hash_func, + eq_func_t eq_func, + double load_limit, + size_t capacity); +void map_destroy(map_t* map); + +bool map_contains(const map_t* map, const void* key); +void* map_get(const map_t* map, const void* key); +void* map_get_or_default(const map_t* map, const void* key, void* default_val); +void* map_compute_if_absent(map_t* map, void* key, void* default_val); +void map_put(map_t* map, void* key, void* val); +void* map_remove(map_t* map, const void* key); + +#endif -- cgit v1.2.3