aboutsummaryrefslogtreecommitdiff
path: root/src/hashtable.h
diff options
context:
space:
mode:
authorkartofen <mladenovnasko0@gmail.com>2024-11-03 17:35:51 +0200
committerkartofen <mladenovnasko0@gmail.com>2024-11-03 17:35:51 +0200
commit0dd38d08551ac2fcff53eb604f6363f37b25aef9 (patch)
treeb9c29e5c0a3467cc6fbec72fb292e5414a8c7f4b /src/hashtable.h
parent7edffea39a3d666098ebeca27ea398769e8b981b (diff)
env is just linked list now, uses much less memory
Diffstat (limited to 'src/hashtable.h')
-rw-r--r--src/hashtable.h54
1 files changed, 0 insertions, 54 deletions
diff --git a/src/hashtable.h b/src/hashtable.h
deleted file mode 100644
index b9b1b2a..0000000
--- a/src/hashtable.h
+++ /dev/null
@@ -1,54 +0,0 @@
-#ifndef HASHMAP_H
-#define HASHMAP_H
-
-#include <stdbool.h>
-
-typedef struct hashtable *hashtable_t;
-
-typedef size_t (*hashtable_hash_func)(void *key);
-typedef bool (*hashtable_equal_func)(void *key1, void *key2);
-
-struct hashtable {
- hashtable_hash_func hash_func;
- hashtable_equal_func equal_func;
-
- struct hashtable_item {
- struct hashtable_item *next;
- void *key;
- void *data;
- } **table;
-
- size_t size;
- size_t cap;
-};
-
-hashtable_t hashtable_create(size_t cap, hashtable_hash_func hash_func, hashtable_equal_func equal_func);
-void hashtable_destroy(hashtable_t ht);
-void hashtable_reset(hashtable_t ht);
-
-int hashtable_insert(hashtable_t ht, void *key, void *data,
- void **prevkey, void **prevdata);
-int hashtable_query(hashtable_t ht, void *key, void **data);
-int hashtable_delete(hashtable_t ht, void *key);
-
-#define hashtable_for_each_item(ht, item, i) \
- for(size_t i = 0; i < ht->cap; i++) \
- for(struct hashtable_item *item = ht->table[i]; \
- item != NULL; \
- item = item->next)
-
-#define hashtable_for_each_item_on_index(ht, item, idx) \
- for(struct hashtable_item *item = \
- ht->table[idx]; \
- item != NULL; \
- item = item->next)
-
-#define hashtable_for_each_item_safe(ht, item, i) \
- for(size_t i = 0; i < ht->cap; i++) \
- for(struct hashtable_item \
- *item = ht->table[i], \
- *next = NULL; \
- item != NULL && (next = item->next, 1); \
- item = next)
-
-#endif