From fe10c0028965ff7ecb5ce46a92205575ded9c7be Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Fri, 27 May 2022 00:22:22 -0700 Subject: [PATCH] Util: Implement HashTableEnumerateCustom --- include/mgba-util/table.h | 2 +- src/util/table.c | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/include/mgba-util/table.h b/include/mgba-util/table.h index b950fcb3b..47908244d 100644 --- a/include/mgba-util/table.h +++ b/include/mgba-util/table.h @@ -70,7 +70,7 @@ void HashTableClear(struct Table*); 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); -void HashTableEnumerateCustom(const struct Table*, void (*handler)(const char* key, void* value, void* user), void* user); +void HashTableEnumerateCustom(const struct Table*, void (*handler)(void* key, void* value, void* user), void* user); const char* HashTableSearch(const struct Table* table, bool (*predicate)(const char* key, const void* value, const void* user), const void* user); const char* HashTableSearchPointer(const struct Table* table, const void* value); const char* HashTableSearchData(const struct Table* table, const void* value, size_t bytes); diff --git a/src/util/table.c b/src/util/table.c index ca256db7a..717d0955f 100644 --- a/src/util/table.c +++ b/src/util/table.c @@ -525,6 +525,17 @@ void HashTableEnumerateBinary(const struct Table* table, void (*handler)(const c } } +void HashTableEnumerateCustom(const struct Table* table, void (*handler)(void* key, void* value, void* user), void* user) { + size_t i; + for (i = 0; i < table->tableSize; ++i) { + const struct TableList* list = &table->table[i]; + size_t j; + for (j = 0; j < list->nEntries; ++j) { + handler((char*) list->list[j].stringKey, list->list[j].value, user); + } + } +} + const char* HashTableSearch(const struct Table* table, bool (*predicate)(const char* key, const void* value, const void* user), const void* user) { size_t i; const char* result = NULL;