summaryrefslogtreecommitdiffstats
path: root/lib/hashtable.h
blob: fe6f5c362d61c81f391a5f9b0153228fc7ebf84e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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