Minor fix to HashMap_itercall(), add to unit test

This commit is contained in:
Stephen Seo 2019-02-15 14:43:16 +09:00
parent 44dd293a4b
commit d0ab9edb20
2 changed files with 12 additions and 2 deletions

View file

@ -349,14 +349,16 @@ void UDPC_HashMap_itercall(UDPC_HashMap *hm, void (*fn)(void*, char*), void *use
{ {
char *data = UDPC_Deque_index_ptr( char *data = UDPC_Deque_index_ptr(
hm->buckets[x], 4 + hm->unitSize, y); hm->buckets[x], 4 + hm->unitSize, y);
fn(userData, data + 4); if(hm->unitSize > 0) { fn(userData, data + 4); }
else { fn(userData, data); }
} }
} }
for(int x = 0; x * (4 + hm->unitSize) < hm->overflow->size; ++x) for(int x = 0; x * (4 + hm->unitSize) < hm->overflow->size; ++x)
{ {
char *data = UDPC_Deque_index_ptr( char *data = UDPC_Deque_index_ptr(
hm->overflow, 4 + hm->unitSize, x); hm->overflow, 4 + hm->unitSize, x);
fn(userData, data + 4); if(hm->unitSize > 0) { fn(userData, data + 4); }
else { fn(userData, data); }
} }
} }

View file

@ -232,6 +232,12 @@ void TEST_ATOSTR()
UNITTEST_REPORT(ATOSTR); UNITTEST_REPORT(ATOSTR);
} }
void TEST_HASHMAP_itercall_comp(void *unused, char *data)
{
int temp = *((int*)(data)) / 100;
ASSERT_EQ_MEM(&temp, data - 4, 4);
}
void TEST_HASHMAP() void TEST_HASHMAP()
{ {
UDPC_HashMap *hm = UDPC_HashMap_init(0, sizeof(int)); UDPC_HashMap *hm = UDPC_HashMap_init(0, sizeof(int));
@ -312,6 +318,8 @@ void TEST_HASHMAP()
ASSERT_EQ_MEM(UDPC_HashMap_get(hm, x), &temp, sizeof(int)); ASSERT_EQ_MEM(UDPC_HashMap_get(hm, x), &temp, sizeof(int));
} }
UDPC_HashMap_itercall(hm, TEST_HASHMAP_itercall_comp, NULL);
// TODO DEBUG // TODO DEBUG
/* /*
printf("Size = %d\n", hm->size); printf("Size = %d\n", hm->size);