all repos — mgba @ 74bb02065d232108192b41eb80e2889e000457bf

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	size_t size;
17	void (*deinitializer)(void*);
18};
19
20void TableInit(struct Table*, size_t initialSize, void (deinitializer(void*)));
21void TableDeinit(struct Table*);
22
23void* TableLookup(const struct Table*, uint32_t key);
24void TableInsert(struct Table*, uint32_t key, void* value);
25
26void TableRemove(struct Table*, uint32_t key);
27void TableClear(struct Table*);
28
29void TableEnumerate(const struct Table*, void (handler(uint32_t key, void* value, void* user)), void* user);
30size_t TableSize(const struct Table*);
31
32static inline void HashTableInit(struct Table* table, size_t initialSize, void (deinitializer(void*))) {
33	TableInit(table, initialSize, deinitializer);
34}
35
36static inline void HashTableDeinit(struct Table* table) {
37	TableDeinit(table);
38}
39
40void* HashTableLookup(const struct Table*, const char* key);
41void HashTableInsert(struct Table*, const char* key, void* value);
42
43void HashTableRemove(struct Table*, const char* key);
44void HashTableClear(struct Table*);
45
46void HashTableEnumerate(const struct Table*, void (handler(const char* key, void* value, void* user)), void* user);
47size_t HashTableSize(const struct Table*);
48
49#endif