From b6861148021df1682f424d3ce8e8051b80889b03 Mon Sep 17 00:00:00 2001 From: Carson Fleming Date: Tue, 4 Aug 2026 23:52:08 -0400 Subject: unify hashmap type --- hashmap.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 hashmap.h (limited to 'hashmap.h') diff --git a/hashmap.h b/hashmap.h new file mode 100644 index 0000000..ff52eb2 --- /dev/null +++ b/hashmap.h @@ -0,0 +1,26 @@ +#ifndef HASHMAP_H +#define HASHMAP_H + +#include "ccc.h" + +#define ADVANCE_HASH(hash, val, cap) (hash = ((hash << 5) - hash + val) % cap) + +typedef integral_t (*hm_hash_fn)(const void*, integral_t); +typedef bool (*hm_eq_fn)(const void*, const void*); +typedef void (*hm_destroy_fn)(void*); + +struct hash_map { + void** entries; + integral_t cap; + + hm_hash_fn hash_fn; + hm_eq_fn eq_fn; + hm_destroy_fn destroy_fn; +}; + +void hm_init(struct hash_map*, hm_hash_fn, hm_eq_fn, hm_destroy_fn); +void hm_destroy(struct hash_map*); +void** hm_cell_r(const struct hash_map*, const void*); +void** hm_cell_w(struct hash_map*, const void*); + +#endif -- cgit v1.2.3