all repos — mgba @ 0870c98c6c285fdafd43f1e5293c9b65972db7a7

mGBA Game Boy Advance Emulator

src/util/table.h (view raw)

 1/* Copyright (c) 2013-2014 Jeffrey Pfau
 2 *
 3 * This Source Code Form is subject to the terms of the Mozilla Public
 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 6#ifndef TABLE_H
 7#define TABLE_H
 8
 9#include "util/common.h"
10
11struct TableList;
12
13struct Table {
14	struct TableList* table;
15	size_t tableSize;
16	void (*deinitializer)(void*);
17};
18
19void TableInit(struct Table*, size_t initialSize, void (deinitializer(void*)));
20void TableDeinit(struct Table*);
21
22void* TableLookup(const struct Table*, uint32_t key);
23void TableInsert(struct Table*, uint32_t key, void* value);
24
25void TableRemove(struct Table*, uint32_t key);
26void TableClear(struct Table*);
27
28void TableEnumerate(const struct Table*, void (handler(uint32_t key, void* value, void* user)), void* user);
29
30static inline void HashTableInit(struct Table* table, size_t initialSize, void (deinitializer(void*))) {
31	TableInit(table, initialSize, deinitializer);
32}
33
34static inline void HashTableDeinit(struct Table* table) {
35	TableDeinit(table);
36}
37
38void* HashTableLookup(const struct Table*, const char* key);
39void HashTableInsert(struct Table*, const char* key, void* value);
40
41void HashTableRemove(struct Table*, const char* key);
42void HashTableClear(struct Table*);
43
44void HashTableEnumerate(const struct Table*, void (handler(const char* key, void* value, void* user)), void* user);
45
46#endif