summaryrefslogtreecommitdiff
path: root/src/ht.h
diff options
context:
space:
mode:
authorJSDurand <mmemmew@gmail.com>2022-01-12 20:26:08 +0800
committerJSDurand <mmemmew@gmail.com>2022-01-12 20:26:08 +0800
commit5730d6c04258e192195bfbbbed76d68fd78ed458 (patch)
tree92e64bd9576155000cf462ed1db3624e3bed3f8d /src/ht.h
parent91016bd3855375796fd1eabd501ebc12491f2655 (diff)
Implement a simple hash table.
It is a very basic and simple hash table. It is so simple that I hesitate to call it a hash table. Anyways, I think it suffices for my purposes here. * Makefile.am: Add necessary files. * grammar.c (new_tnt_string): Formatting. * ht.c (new_ht): Constructor (destroy_ht): Destructor (ht_expand): Rehash (ht_insert, ht_delete, ht_find): Main functions. * list.c (add_to_list, list_assure_size): Modify the use of realloc. * test/check_ht.c: Ensure this is working correctly. * util.c (read_entire_file): Modify the use of realloc.
Diffstat (limited to 'src/ht.h')
-rw-r--r--src/ht.h23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/ht.h b/src/ht.h
new file mode 100644
index 0000000..54c0497
--- /dev/null
+++ b/src/ht.h
@@ -0,0 +1,23 @@
+#ifndef HT_H
+#define HT_H
+#include "util.h"
+
+enum { HT_INIT_CAP = 257 };
+
+typedef struct ht_s ht;
+
+ht *new_ht(UNUM size);
+
+void destroy_ht(ht * restrict htp, int flag);
+
+BOOL ht_insert(ht *htp, NUM key, void *value);
+
+/* This is just for the completeness. In theory I do not need to
+ delete keys.
+
+ If FLAG is non-zero, also free the value pointer. */
+BOOL ht_delete(ht * const restrict htp, NUM key, int flag);
+
+void *ht_find(ht * const restrict htp, NUM key);
+
+#endif