aboutsummaryrefslogtreecommitdiff
path: root/src/include/hash_table.h
diff options
context:
space:
mode:
authorPreston Pan <ret2pop@gmail.com>2025-01-30 21:02:42 -0800
committerPreston Pan <ret2pop@gmail.com>2025-01-30 21:02:42 -0800
commit3780f207f924f14734cb839fd015bd883fe52ff1 (patch)
treede13568dbf97ffe477943854bcb3ea6001b46cf8 /src/include/hash_table.h
parentef9ab1fd141f4057d41f2d6ed8ab8d67c44894d5 (diff)
restructure projectHEADmain
Diffstat (limited to 'src/include/hash_table.h')
-rw-r--r--src/include/hash_table.h31
1 files changed, 30 insertions, 1 deletions
diff --git a/src/include/hash_table.h b/src/include/hash_table.h
index 8f19635..55136ba 100644
--- a/src/include/hash_table.h
+++ b/src/include/hash_table.h
@@ -2,16 +2,21 @@
#define HASH_TABLE_H
#include "list.h"
#include <stdlib.h>
+
#define DEFAULT_HT_SIZE 500
typedef struct PAIR_STRUCT {
- char *key;
+ union {
+ char *key;
+ int ikey;
+ };
void *v;
} pair_t;
typedef struct {
list_t **buckets;
size_t size;
+ bool is_map;
} ht_t;
pair_t *init_pair(char *key, void *value);
@@ -22,10 +27,34 @@ void *bucket_pop(list_t *b, char *key);
void bucket_free(void *x, void (*freefunc)(void *));
+pair_t *init_long_pair(unsigned long key, void *value);
+
+void *bucket_get_by_long(list_t *b, unsigned long key);
+
+void *bucket_pop_by_long(list_t *b, unsigned long key);
+
+void bucket_free_with_long(void *x, void (*freefunc)(void *));
+
ht_t *init_ht(size_t size);
+ht_t *init_map(size_t size);
+
+void map_insert(ht_t *ht, unsigned long key, void *value);
+
+void *map_pop(ht_t *ht, unsigned long key);
+
+void *map_get(ht_t *ht, unsigned long key);
+
+void map_free(void *x);
+
void ht_insert(ht_t *ht, char *key, void *value);
+/*! @brief returns the old value, mutates ht state with new value */
+void *ht_modify(ht_t *ht, char *key, void *newval);
+
+/*! @brief overwrites old value with new value while freeing the old */
+void ht_overwrite(ht_t *ht, char *key, void *newval, void (*freefunc)(void *));
+
void *ht_pop(ht_t *ht, char *key);
void *ht_get(ht_t *ht, char *key);