From 9f342255a2260480701cc2ac2d0c623d4aba1348 Mon Sep 17 00:00:00 2001 From: Preston Pan Date: Tue, 3 Jan 2023 00:27:06 -0800 Subject: add some comments; fix some bugs in advance --- src/hash_table.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/hash_table.c') diff --git a/src/hash_table.c b/src/hash_table.c index 9384945..3ca6dd0 100644 --- a/src/hash_table.c +++ b/src/hash_table.c @@ -70,6 +70,12 @@ ast_t *sl_list_get(sl_list_t *l, char *key) { return NULL; } +bool sl_list_exists(sl_list_l, char *key) { + if (sl_list_get(l, key) != NULL) + return true; + return false; +} + void sl_list_free(sl_list_t *l) { sl_node_t *cur = l->head; sl_node_t *tmp; @@ -111,6 +117,11 @@ void hash_table_free(hash_table_t *h) { free(h); } +bool hash_table_exists(hash_table_t *h, char *key) { + sl_list_t *l = h->buckets[hash(key, h->size)]; + return sl_list_exists(l, key); +} + /* DJB2 HASH FUNCTION */ unsigned long hash(char *key, int size) { unsigned long hash = 5381; -- cgit