include/mgba-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 <mgba-util/common.h>
10
11CXX_GUARD_START
12
13struct TableList;
14
15struct Table {
16 struct TableList* table;
17 size_t tableSize;
18 size_t size;
19 void (*deinitializer)(void*);
20};
21
22void TableInit(struct Table*, size_t initialSize, void (deinitializer(void*)));
23void TableDeinit(struct Table*);
24
25void* TableLookup(const struct Table*, uint32_t key);
26void TableInsert(struct Table*, uint32_t key, void* value);
27
28void TableRemove(struct Table*, uint32_t key);
29void TableClear(struct Table*);
30
31void TableEnumerate(const struct Table*, void (handler(uint32_t key, void* value, void* user)), void* user);
32size_t TableSize(const struct Table*);
33
34void HashTableInit(struct Table* table, size_t initialSize, void (deinitializer(void*)));
35void HashTableDeinit(struct Table* table);
36
37void* HashTableLookup(const struct Table*, const char* key);
38void* HashTableLookupBinary(const struct Table*, const void* key, size_t keylen);
39void HashTableInsert(struct Table*, const char* key, void* value);
40void HashTableInsertBinary(struct Table*, const void* key, size_t keylen, void* value);
41
42void HashTableRemove(struct Table*, const char* key);
43void HashTableRemoveBinary(struct Table*, const void* key, size_t keylen);
44void HashTableClear(struct Table*);
45
46void HashTableEnumerate(const struct Table*, void (handler(const char* key, void* value, void* user)), void* user);
47const char* HashTableSearch(const struct Table* table, bool (predicate(const char* key, const void* value, const void* user)), const void* user);
48const char* HashTableSearchPointer(const struct Table* table, const void* value);
49const char* HashTableSearchData(const struct Table* table, const void* value, size_t bytes);
50const char* HashTableSearchString(const struct Table* table, const char* value);
51size_t HashTableSize(const struct Table*);
52
53CXX_GUARD_END
54
55#endif