diff options
Diffstat (limited to 'lib/hashtable.h')
-rw-r--r-- | lib/hashtable.h | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/hashtable.h b/lib/hashtable.h new file mode 100644 index 0000000..fe6f5c3 --- /dev/null +++ b/lib/hashtable.h @@ -0,0 +1,34 @@ +#ifndef JOVE_LIB_HASHTABLE_H +#define JOVE_LIB_HASHTABLE_H 1 + +#include <stddef.h> +#include <stdint.h> +#include "linkedlist.h" + +struct HashTableValue +{ + const void *key; + char value[]; +}; + +struct HashTable { + struct SLinkedList *buckets; + size_t bucket_count; + size_t bucket_capacity; + + size_t obj_size; + int key_size; + size_t (*hash_function)(const void*, size_t); +}; + +void _hashtable_new(struct HashTable *table, size_t obj_size, size_t key_size); +#define hashtable_new(table, type, keytype) _hashtable_new(table, sizeof(type), sizeof(keytype)) + +void _hashtable_news(struct HashTable *table, size_t obj_size); +#define hashtable_news(table, type) _hashtable_news(table, sizeof(type)) + +void hashtable_insert(struct HashTable *table, const void *key, void *data); +void *_hashtable_get(struct HashTable *table, const void *key); +#define hashtable_get(table, key, type) (type*)_hashtable_get(table, key) + +#endif |