summaryrefslogtreecommitdiff
path: root/map.h
diff options
context:
space:
mode:
authorCarson Fleming <[email protected]>2026-02-01 03:23:32 -0500
committerCarson Fleming <[email protected]>2026-02-01 03:23:32 -0500
commit9500e54b874794bd1d9fb5702aa423c6f1794f27 (patch)
treeb2a76b9421c2b05b688b566e46bc061e9856d009 /map.h
parentb364a39849fc4a6f6837f8558b7520efc24ae96c (diff)
downloadsafec-9500e54b874794bd1d9fb5702aa423c6f1794f27.tar.gz
add map library
Diffstat (limited to 'map.h')
-rw-r--r--map.h44
1 files changed, 44 insertions, 0 deletions
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