summaryrefslogtreecommitdiff
path: root/hashtbl.h
diff options
context:
space:
mode:
Diffstat (limited to 'hashtbl.h')
-rw-r--r--hashtbl.h40
1 files changed, 40 insertions, 0 deletions
diff --git a/hashtbl.h b/hashtbl.h
new file mode 100644
index 0000000..cc3daff
--- /dev/null
+++ b/hashtbl.h
@@ -0,0 +1,40 @@
+/*
+ * hashtbl.h
+ *
+ * Efficient dictionary hash table class.
+ */
+
+#ifndef NASM_HASHTBL_H
+#define NASM_HASHTBL_H
+
+#include <inttypes.h>
+#include <stddef.h>
+#include "nasmlib.h"
+
+struct hash_tbl_node {
+ uint64_t hash;
+ const char *key;
+ void *data;
+};
+
+struct hash_table {
+ struct hash_tbl_node *table;
+ size_t load;
+ size_t size;
+ size_t max_load;
+};
+
+struct hash_insert {
+ uint64_t hash;
+ struct hash_table *head;
+ struct hash_tbl_node *where;
+};
+
+uint64_t crc64(const char *string);
+struct hash_table *hash_init(void);
+void *hash_find(struct hash_table *head, const char *string,
+ struct hash_insert *insert);
+void hash_add(struct hash_insert *insert, const char *string, void *data);
+void hash_free(struct hash_table *head, void (*free_func)(char *, void *));
+
+#endif /* NASM_HASHTBL_H */