diff --git a/CHANGES b/CHANGES index e0ea79be4..8286b8219 100644 --- a/CHANGES +++ b/CHANGES @@ -39,6 +39,7 @@ Misc: - Debugger: Make building with debugging aspects optional - GBA Memory: Support for Mo Jie Qi Bing by Vast Fame (taizou) - GBA Memory: Support reading/writing POSTFLG + - Util: Add size counting to Table 0.5.1: (2016-10-05) Bugfixes: diff --git a/src/util/table.c b/src/util/table.c index cc01f2c67..09f40064d 100644 --- a/src/util/table.c +++ b/src/util/table.c @@ -54,6 +54,7 @@ static struct TableList* _resizeAsNeeded(struct Table* table, struct TableList* static void _removeItemFromList(struct Table* table, struct TableList* list, size_t item) { --list->nEntries; + --table->size; free(list->list[item].stringKey); if (table->deinitializer) { table->deinitializer(list->list[item].value); @@ -119,6 +120,7 @@ void TableInsert(struct Table* table, uint32_t key, void* value) { list->list[list->nEntries].stringKey = 0; list->list[list->nEntries].value = value; ++list->nEntries; + ++table->size; } void TableRemove(struct Table* table, uint32_t key) { @@ -156,6 +158,10 @@ void TableEnumerate(const struct Table* table, void (handler(uint32_t key, void* } } +size_t TableSize(const struct Table* table) { + return table->size; +} + void* HashTableLookup(const struct Table* table, const char* key) { uint32_t hash = hash32(key, strlen(key), 0); const struct TableList* list; @@ -181,6 +187,7 @@ void HashTableInsert(struct Table* table, const char* key, void* value) { list->list[list->nEntries].keylen = strlen(key); list->list[list->nEntries].value = value; ++list->nEntries; + ++table->size; } void HashTableRemove(struct Table* table, const char* key) { @@ -219,3 +226,7 @@ void HashTableEnumerate(const struct Table* table, void (handler(const char* key } } } + +size_t HashTableSize(const struct Table* table) { + return table->size; +} diff --git a/src/util/table.h b/src/util/table.h index 3c21c40ff..5dee643fd 100644 --- a/src/util/table.h +++ b/src/util/table.h @@ -13,6 +13,7 @@ struct TableList; struct Table { struct TableList* table; size_t tableSize; + size_t size; void (*deinitializer)(void*); }; @@ -26,6 +27,7 @@ void TableRemove(struct Table*, uint32_t key); void TableClear(struct Table*); void TableEnumerate(const struct Table*, void (handler(uint32_t key, void* value, void* user)), void* user); +size_t TableSize(const struct Table*); static inline void HashTableInit(struct Table* table, size_t initialSize, void (deinitializer(void*))) { TableInit(table, initialSize, deinitializer); @@ -42,5 +44,6 @@ void HashTableRemove(struct Table*, const char* key); void HashTableClear(struct Table*); void HashTableEnumerate(const struct Table*, void (handler(const char* key, void* value, void* user)), void* user); +size_t HashTableSize(const struct Table*); #endif