summaryrefslogtreecommitdiff
path: root/hashmap.h
diff options
context:
space:
mode:
authorCarson Fleming <cflems@cflems.net>2026-08-04 23:52:08 -0400
committerCarson Fleming <cflems@cflems.net>2026-08-04 23:52:08 -0400
commitb6861148021df1682f424d3ce8e8051b80889b03 (patch)
treed36a8dc9853ba7eddd58acf814a1caf9c0e1acfa /hashmap.h
parentebe7f44385c4be54afd2993d54ce6352f612f9fa (diff)
downloadccc-b6861148021df1682f424d3ce8e8051b80889b03.tar.gz
unify hashmap type
Diffstat (limited to 'hashmap.h')
-rw-r--r--hashmap.h26
1 files changed, 26 insertions, 0 deletions
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