aboutsummaryrefslogtreecommitdiff
path: root/src/hash_table.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/hash_table.h')
-rw-r--r--src/hash_table.h29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/hash_table.h b/src/hash_table.h
new file mode 100644
index 0000000..1bf6cfe
--- /dev/null
+++ b/src/hash_table.h
@@ -0,0 +1,29 @@
+#ifndef HTABLE_H_
+#define HTABLE_H_
+
+#include <stdbool.h>
+#include <stdint.h>
+
+struct hash_table {
+ void *buf;
+ int64_t size;
+ int64_t cap;
+ int64_t taken;
+ void *begin;
+ int64_t elemsz;
+ uint64_t (*hash)(void *);
+ bool (*eq)(void *, void *);
+};
+typedef struct hash_table hash_table_t;
+
+void init_hash_table(hash_table_t *ht, int64_t elemsz, int64_t cap,
+ uint64_t (*hash)(void *), bool (*eq)(void *, void *));
+bool hash_table_insert(hash_table_t *ht, void *elem);
+void hash_table_remove(hash_table_t *ht, void *iter);
+
+// return a iterator
+void *hash_table_find(hash_table_t *ht, void *elem);
+void *hash_table_begin(hash_table_t *ht);
+void *hash_table_next(hash_table_t *ht, void *iter);
+
+#endif