all repos — mgba @ bb7d85698bd863d1108af18f93efc72a91560858

mGBA Game Boy Advance Emulator

Util: Add size counting to Table
Jeffrey Pfau jeffrey@endrift.com
Mon, 31 Oct 2016 23:45:14 -0700
commit

bb7d85698bd863d1108af18f93efc72a91560858

parent

0870c98c6c285fdafd43f1e5293c9b65972db7a7

3 files changed, 15 insertions(+), 0 deletions(-)

jump to
M CHANGESCHANGES

@@ -39,6 +39,7 @@ - Core: Clean up some thread state checks

- 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:
M src/util/table.csrc/util/table.c

@@ -54,6 +54,7 @@ }

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 @@ list->list[list->nEntries].key = key;

list->list[list->nEntries].stringKey = 0; list->list[list->nEntries].value = value; ++list->nEntries; + ++table->size; } void TableRemove(struct Table* table, uint32_t key) {

@@ -154,6 +156,10 @@ for (j = 0; j < list->nEntries; ++j) {

handler(list->list[j].key, list->list[j].value, user); } } +} + +size_t TableSize(const struct Table* table) { + return table->size; } void* HashTableLookup(const struct Table* table, const char* key) {

@@ -181,6 +187,7 @@ list->list[list->nEntries].stringKey = strdup(key);

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 @@ handler(list->list[j].stringKey, list->list[j].value, user);

} } } + +size_t HashTableSize(const struct Table* table) { + return table->size; +}
M src/util/table.hsrc/util/table.h

@@ -13,6 +13,7 @@

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