src/util/table.h (view raw)
1#ifndef TABLE_H
2#define TABLE_H
3
4#include "util/common.h"
5
6struct TableList;
7
8struct Table {
9 struct TableList* table;
10 size_t tableSize;
11 void (*deinitializer)(void*);
12};
13
14void TableInit(struct Table*, size_t initialSize, void (deinitializer(void*)));
15void TableDeinit(struct Table*);
16
17void* TableLookup(const struct Table*, uint32_t key);
18void TableInsert(struct Table*, uint32_t key, void* value);
19
20void TableRemove(struct Table*, uint32_t key);
21void TableClear(struct Table*);
22
23void TableEnumerate(const struct Table*, void (handler(void* value, void* user)), void* user);
24
25static inline void HashTableInit(struct Table* table, size_t initialSize, void (deinitializer(void*))) {
26 TableInit(table, initialSize, deinitializer);
27}
28
29static inline void HashTableDeinit(struct Table* table) {
30 TableDeinit(table);
31}
32
33void* HashTableLookup(const struct Table*, const char* key);
34void HashTableInsert(struct Table*, const char* key, void* value);
35
36void HashTableRemove(struct Table*, const char* key);
37void HashTableClear(struct Table*);
38
39void HashTableEnumerate(const struct Table*, void (handler(const char* key, void* value, void* user)), void* user);
40
41#endif