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 uint32_t seed;
21};
22
23void TableInit(struct Table*, size_t initialSize, void (*deinitializer)(void*));
24void TableDeinit(struct Table*);
25
26void* TableLookup(const struct Table*, uint32_t key);
27void TableInsert(struct Table*, uint32_t key, void* value);
28
29void TableRemove(struct Table*, uint32_t key);
30void TableClear(struct Table*);
31
32void TableEnumerate(const struct Table*, void (*handler)(uint32_t key, void* value, void* user), void* user);
33size_t TableSize(const struct Table*);
34
35void HashTableInit(struct Table* table, size_t initialSize, void (*deinitializer)(void*));
36void HashTableDeinit(struct Table* table);
37
38void* HashTableLookup(const struct Table*, const char* key);
39void* HashTableLookupBinary(const struct Table*, const void* key, size_t keylen);
40void HashTableInsert(struct Table*, const char* key, void* value);
41void HashTableInsertBinary(struct Table*, const void* key, size_t keylen, void* value);
42
43void HashTableRemove(struct Table*, const char* key);
44void HashTableRemoveBinary(struct Table*, const void* key, size_t keylen);
45void HashTableClear(struct Table*);
46
47void HashTableEnumerate(const struct Table*, void (*handler)(const char* key, void* value, void* user), void* user);
48void HashTableEnumerateBinary(const struct Table*, void (*handler)(const char* key, size_t keylen, void* value, void* user), void* user);
49const char* HashTableSearch(const struct Table* table, bool (*predicate)(const char* key, const void* value, const void* user), const void* user);
50const char* HashTableSearchPointer(const struct Table* table, const void* value);
51const char* HashTableSearchData(const struct Table* table, const void* value, size_t bytes);
52const char* HashTableSearchString(const struct Table* table, const char* value);
53size_t HashTableSize(const struct Table*);
54
55CXX_GUARD_END
56
57#endif