aboutsummaryrefslogtreecommitdiff
path: root/src/include/hash_table.h
diff options
context:
space:
mode:
authorPreston Pan <ret2pop@gmail.com>2025-01-09 16:32:55 -0800
committerPreston Pan <ret2pop@gmail.com>2025-01-09 16:32:55 -0800
commitef9ab1fd141f4057d41f2d6ed8ab8d67c44894d5 (patch)
treee4005b7a641303b021eb54c2aae5676b5f92a72d /src/include/hash_table.h
parent1fd608288ee47c2c560817f12f14b21069fed2f6 (diff)
save stateHEADmain
Diffstat (limited to 'src/include/hash_table.h')
-rw-r--r--src/include/hash_table.h32
1 files changed, 13 insertions, 19 deletions
diff --git a/src/include/hash_table.h b/src/include/hash_table.h
index ea21e37..8f19635 100644
--- a/src/include/hash_table.h
+++ b/src/include/hash_table.h
@@ -1,6 +1,6 @@
#ifndef HASH_TABLE_H
#define HASH_TABLE_H
-
+#include "list.h"
#include <stdlib.h>
#define DEFAULT_HT_SIZE 500
@@ -9,35 +9,29 @@ typedef struct PAIR_STRUCT {
void *v;
} pair_t;
-typedef struct NODE_STRUCT {
- char *key;
- void *v;
- struct NODE_STRUCT *next;
-} node_t;
-
-typedef struct {
- node_t *head;
- node_t *tail;
-} sll_t;
-
typedef struct {
- sll_t **buckets;
+ list_t **buckets;
size_t size;
} ht_t;
-node_t *init_node(char *key, void *v);
+pair_t *init_pair(char *key, void *value);
+
+void *bucket_get(list_t *b, char *key);
-void sll_push(sll_t *sll, char *key, void *v);
+void *bucket_pop(list_t *b, char *key);
-void sll_delete(sll_t *sll, char *key);
+void bucket_free(void *x, void (*freefunc)(void *));
-sll_t *sll_free(void *x, void (*freefunc)(void *));
+ht_t *init_ht(size_t size);
void ht_insert(ht_t *ht, char *key, void *value);
-void ht_delete(ht_t *ht, char *key);
+void *ht_pop(ht_t *ht, char *key);
void *ht_get(ht_t *ht, char *key);
-ht_t *init_ht(size_t size);
+void ht_free(void *x, void (*freefunc)(void *));
+
+/* djb2 hash function */
+unsigned long hash(char *key);
#endif