mirror of https://github.com/mgba-emu/mgba.git
Util: Add size counting to Table
This commit is contained in:
parent
0870c98c6c
commit
bb7d85698b
1
CHANGES
1
CHANGES
|
@ -39,6 +39,7 @@ Misc:
|
||||||
- Debugger: Make building with debugging aspects optional
|
- Debugger: Make building with debugging aspects optional
|
||||||
- GBA Memory: Support for Mo Jie Qi Bing by Vast Fame (taizou)
|
- GBA Memory: Support for Mo Jie Qi Bing by Vast Fame (taizou)
|
||||||
- GBA Memory: Support reading/writing POSTFLG
|
- GBA Memory: Support reading/writing POSTFLG
|
||||||
|
- Util: Add size counting to Table
|
||||||
|
|
||||||
0.5.1: (2016-10-05)
|
0.5.1: (2016-10-05)
|
||||||
Bugfixes:
|
Bugfixes:
|
||||||
|
|
|
@ -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) {
|
static void _removeItemFromList(struct Table* table, struct TableList* list, size_t item) {
|
||||||
--list->nEntries;
|
--list->nEntries;
|
||||||
|
--table->size;
|
||||||
free(list->list[item].stringKey);
|
free(list->list[item].stringKey);
|
||||||
if (table->deinitializer) {
|
if (table->deinitializer) {
|
||||||
table->deinitializer(list->list[item].value);
|
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].stringKey = 0;
|
||||||
list->list[list->nEntries].value = value;
|
list->list[list->nEntries].value = value;
|
||||||
++list->nEntries;
|
++list->nEntries;
|
||||||
|
++table->size;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TableRemove(struct Table* table, uint32_t key) {
|
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) {
|
void* HashTableLookup(const struct Table* table, const char* key) {
|
||||||
uint32_t hash = hash32(key, strlen(key), 0);
|
uint32_t hash = hash32(key, strlen(key), 0);
|
||||||
const struct TableList* list;
|
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].keylen = strlen(key);
|
||||||
list->list[list->nEntries].value = value;
|
list->list[list->nEntries].value = value;
|
||||||
++list->nEntries;
|
++list->nEntries;
|
||||||
|
++table->size;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HashTableRemove(struct Table* table, const char* key) {
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ struct TableList;
|
||||||
struct Table {
|
struct Table {
|
||||||
struct TableList* table;
|
struct TableList* table;
|
||||||
size_t tableSize;
|
size_t tableSize;
|
||||||
|
size_t size;
|
||||||
void (*deinitializer)(void*);
|
void (*deinitializer)(void*);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -26,6 +27,7 @@ void TableRemove(struct Table*, uint32_t key);
|
||||||
void TableClear(struct Table*);
|
void TableClear(struct Table*);
|
||||||
|
|
||||||
void TableEnumerate(const struct Table*, void (handler(uint32_t key, void* value, void* user)), void* user);
|
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*))) {
|
static inline void HashTableInit(struct Table* table, size_t initialSize, void (deinitializer(void*))) {
|
||||||
TableInit(table, initialSize, deinitializer);
|
TableInit(table, initialSize, deinitializer);
|
||||||
|
@ -42,5 +44,6 @@ void HashTableRemove(struct Table*, const char* key);
|
||||||
void HashTableClear(struct Table*);
|
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);
|
||||||
|
size_t HashTableSize(const struct Table*);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue