diff --git a/src/util/table.c b/src/util/table.c index 9b0f62905..be314ae55 100644 --- a/src/util/table.c +++ b/src/util/table.c @@ -121,6 +121,15 @@ void TableInsert(struct Table* table, uint32_t key, void* value) { ++list->nEntries; } +size_t TableSize(const struct Table* table) { + size_t e = 0; + size_t i; + for (i = 0; i < table->tableSize; ++i) { + e += table->table[i].nEntries; + } + return e; +} + void TableRemove(struct Table* table, uint32_t key) { struct TableList* list; TABLE_LOOKUP_START(TABLE_COMPARATOR, list, key) { diff --git a/src/util/table.h b/src/util/table.h index 3c21c40ff..451e92d06 100644 --- a/src/util/table.h +++ b/src/util/table.h @@ -24,6 +24,7 @@ void TableInsert(struct Table*, uint32_t key, void* value); void TableRemove(struct Table*, uint32_t key); void TableClear(struct Table*); +size_t TableSize(const struct Table*); void TableEnumerate(const struct Table*, void (handler(uint32_t key, void* value, void* user)), void* user); @@ -35,6 +36,10 @@ static inline void HashTableDeinit(struct Table* table) { TableDeinit(table); } +static inline size_t HashTableSize(const struct Table* table) { + return TableSize(table); +} + void* HashTableLookup(const struct Table*, const char* key); void HashTableInsert(struct Table*, const char* key, void* value);