summaryrefslogtreecommitdiff
path: root/hashmap.h
diff options
context:
space:
mode:
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