2014-12-03 08:39:06 +00:00
|
|
|
/* Copyright (c) 2013-2014 Jeffrey Pfau
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2014-10-12 07:44:45 +00:00
|
|
|
#ifndef TABLE_H
|
|
|
|
#define TABLE_H
|
|
|
|
|
2016-12-31 01:00:22 +00:00
|
|
|
#include <mgba-util/common.h>
|
2014-10-12 07:44:45 +00:00
|
|
|
|
2016-12-27 05:01:55 +00:00
|
|
|
CXX_GUARD_START
|
|
|
|
|
2014-10-12 07:44:45 +00:00
|
|
|
struct TableList;
|
2021-08-30 01:23:50 +00:00
|
|
|
typedef uint32_t (*HashFunction)(const void* key, size_t len, uint32_t seed);
|
|
|
|
|
|
|
|
struct TableFunctions {
|
|
|
|
void (*deinitializer)(void*);
|
|
|
|
HashFunction hash;
|
|
|
|
bool (*equal)(const void*, const void*);
|
|
|
|
void* (*ref)(void*);
|
|
|
|
void (*deref)(void*);
|
|
|
|
};
|
2014-10-12 07:44:45 +00:00
|
|
|
|
|
|
|
struct Table {
|
|
|
|
struct TableList* table;
|
|
|
|
size_t tableSize;
|
2016-11-01 06:45:14 +00:00
|
|
|
size_t size;
|
2020-08-17 07:51:00 +00:00
|
|
|
uint32_t seed;
|
2021-08-30 01:23:50 +00:00
|
|
|
struct TableFunctions fn;
|
2014-10-12 07:44:45 +00:00
|
|
|
};
|
|
|
|
|
2022-05-15 08:17:53 +00:00
|
|
|
struct TableIterator {
|
|
|
|
size_t bucket;
|
|
|
|
size_t entry;
|
|
|
|
};
|
|
|
|
|
2020-08-17 07:51:00 +00:00
|
|
|
void TableInit(struct Table*, size_t initialSize, void (*deinitializer)(void*));
|
2014-10-12 07:44:45 +00:00
|
|
|
void TableDeinit(struct Table*);
|
|
|
|
|
2014-11-01 10:02:10 +00:00
|
|
|
void* TableLookup(const struct Table*, uint32_t key);
|
2014-10-12 07:44:45 +00:00
|
|
|
void TableInsert(struct Table*, uint32_t key, void* value);
|
|
|
|
|
2014-11-01 10:02:10 +00:00
|
|
|
void TableRemove(struct Table*, uint32_t key);
|
|
|
|
void TableClear(struct Table*);
|
|
|
|
|
2020-08-17 07:51:00 +00:00
|
|
|
void TableEnumerate(const struct Table*, void (*handler)(uint32_t key, void* value, void* user), void* user);
|
2016-11-01 06:45:14 +00:00
|
|
|
size_t TableSize(const struct Table*);
|
2014-11-01 10:02:10 +00:00
|
|
|
|
2022-05-15 08:17:53 +00:00
|
|
|
bool TableIteratorStart(const struct Table*, struct TableIterator*);
|
|
|
|
bool TableIteratorNext(const struct Table*, struct TableIterator*);
|
|
|
|
uint32_t TableIteratorGetKey(const struct Table*, const struct TableIterator*);
|
|
|
|
void* TableIteratorGetValue(const struct Table*, const struct TableIterator*);
|
|
|
|
bool TableIteratorLookup(const struct Table*, struct TableIterator*, uint32_t key);
|
|
|
|
|
2020-08-17 07:51:00 +00:00
|
|
|
void HashTableInit(struct Table* table, size_t initialSize, void (*deinitializer)(void*));
|
2021-08-30 01:23:50 +00:00
|
|
|
void HashTableInitCustom(struct Table* table, size_t initialSize, const struct TableFunctions* funcs);
|
2016-10-11 20:13:44 +00:00
|
|
|
void HashTableDeinit(struct Table* table);
|
2014-11-01 10:02:10 +00:00
|
|
|
|
|
|
|
void* HashTableLookup(const struct Table*, const char* key);
|
2020-08-01 00:22:18 +00:00
|
|
|
void* HashTableLookupBinary(const struct Table*, const void* key, size_t keylen);
|
2021-08-30 01:23:50 +00:00
|
|
|
void* HashTableLookupCustom(const struct Table*, void* key);
|
2014-11-01 10:02:10 +00:00
|
|
|
void HashTableInsert(struct Table*, const char* key, void* value);
|
2020-08-01 00:22:18 +00:00
|
|
|
void HashTableInsertBinary(struct Table*, const void* key, size_t keylen, void* value);
|
2021-08-30 01:23:50 +00:00
|
|
|
void HashTableInsertCustom(struct Table*, void* key, void* value);
|
2014-11-01 10:02:10 +00:00
|
|
|
|
|
|
|
void HashTableRemove(struct Table*, const char* key);
|
2020-08-01 00:22:18 +00:00
|
|
|
void HashTableRemoveBinary(struct Table*, const void* key, size_t keylen);
|
2021-08-30 01:23:50 +00:00
|
|
|
void HashTableRemoveCustom(struct Table*, void* key);
|
2014-11-01 10:02:10 +00:00
|
|
|
void HashTableClear(struct Table*);
|
|
|
|
|
2020-08-17 07:51:00 +00:00
|
|
|
void HashTableEnumerate(const struct Table*, void (*handler)(const char* key, void* value, void* user), void* user);
|
|
|
|
void HashTableEnumerateBinary(const struct Table*, void (*handler)(const char* key, size_t keylen, void* value, void* user), void* user);
|
2022-05-27 07:22:22 +00:00
|
|
|
void HashTableEnumerateCustom(const struct Table*, void (*handler)(void* key, void* value, void* user), void* user);
|
2020-08-17 07:51:00 +00:00
|
|
|
const char* HashTableSearch(const struct Table* table, bool (*predicate)(const char* key, const void* value, const void* user), const void* user);
|
2020-08-01 00:22:18 +00:00
|
|
|
const char* HashTableSearchPointer(const struct Table* table, const void* value);
|
|
|
|
const char* HashTableSearchData(const struct Table* table, const void* value, size_t bytes);
|
|
|
|
const char* HashTableSearchString(const struct Table* table, const char* value);
|
2016-11-01 06:45:14 +00:00
|
|
|
size_t HashTableSize(const struct Table*);
|
2014-11-01 10:02:10 +00:00
|
|
|
|
2022-05-15 08:17:53 +00:00
|
|
|
bool HashTableIteratorStart(const struct Table*, struct TableIterator*);
|
|
|
|
bool HashTableIteratorNext(const struct Table*, struct TableIterator*);
|
|
|
|
const char* HashTableIteratorGetKey(const struct Table*, const struct TableIterator*);
|
|
|
|
const void* HashTableIteratorGetBinaryKey(const struct Table*, const struct TableIterator*);
|
|
|
|
size_t HashTableIteratorGetBinaryKeyLen(const struct Table*, const struct TableIterator*);
|
|
|
|
void* HashTableIteratorGetCustomKey(const struct Table*, const struct TableIterator*);
|
|
|
|
void* HashTableIteratorGetValue(const struct Table*, const struct TableIterator*);
|
|
|
|
bool HashTableIteratorLookup(const struct Table*, struct TableIterator*, const char* key);
|
|
|
|
bool HashTableIteratorLookupBinary(const struct Table*, struct TableIterator*, const void* key, size_t keylen);
|
|
|
|
bool HashTableIteratorLookupCustom(const struct Table*, struct TableIterator*, void* key);
|
|
|
|
|
2016-12-27 05:01:55 +00:00
|
|
|
CXX_GUARD_END
|
|
|
|
|
2014-10-12 07:44:45 +00:00
|
|
|
#endif
|