Util: Implement HashTableEnumerateCustom

This commit is contained in:
Vicki Pfau 2022-05-27 00:22:22 -07:00
parent a7710ed8d5
commit fe10c00289
2 changed files with 12 additions and 1 deletions

View File

@ -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 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 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* 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* HashTableSearchPointer(const struct Table* table, const void* value);
const char* HashTableSearchData(const struct Table* table, const void* value, size_t bytes); const char* HashTableSearchData(const struct Table* table, const void* value, size_t bytes);

View File

@ -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) { const char* HashTableSearch(const struct Table* table, bool (*predicate)(const char* key, const void* value, const void* user), const void* user) {
size_t i; size_t i;
const char* result = NULL; const char* result = NULL;