summaryrefslogtreecommitdiff
path: root/src/include/hash_table.h
diff options
context:
space:
mode:
authorPreston Pan <preston@nullring.xyz>2023-01-02 22:31:49 -0800
committerPreston Pan <preston@nullring.xyz>2023-01-02 22:31:49 -0800
commit64feef1b9ea72adf7ba32998e9dca7d507607498 (patch)
treea409e61877bb51aa6fb2477175dabbf3dbccf298 /src/include/hash_table.h
a lot of stuff.
Diffstat (limited to 'src/include/hash_table.h')
-rw-r--r--src/include/hash_table.h47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/include/hash_table.h b/src/include/hash_table.h
new file mode 100644
index 0000000..df2d368
--- /dev/null
+++ b/src/include/hash_table.h
@@ -0,0 +1,47 @@
+#ifndef HASH_TABLE_H
+#define HASH_TABLE_H
+#include "./ast.h"
+
+typedef struct {
+ char *key;
+ ast_t *value;
+} pair_t;
+
+typedef struct SL_NODE_STRUCT {
+ pair_t *value;
+ struct SL_NODE_STRUCT *next;
+} sl_node_t;
+
+typedef struct {
+ sl_node_t *head;
+ int size;
+} sl_list_t;
+
+typedef struct {
+ int size;
+ sl_list_t **buckets;
+} hash_table_t;
+
+pair_t *init_pair(char *key, ast_t *value);
+
+sl_node_t *init_sl_node(char *key, ast_t *value);
+
+sl_list_t *init_sl_list();
+
+void sl_list_add(sl_list_t *l, char *key, ast_t *value);
+
+ast_t *sl_list_get(sl_list_t *l, char *key);
+
+void sl_list_free(sl_list_t *l);
+
+hash_table_t *init_hash_table(int size);
+
+void hash_table_add(hash_table_t *h, char *key, ast_t *value);
+
+ast_t *hash_table_get(hash_table_t *h, char *key);
+
+unsigned long hash(char *key, int size);
+
+void hash_table_free(hash_table_t *h);
+
+#endif