hashmap: use *_entry APIs for iteration
Inspired by list_for_each_entry in the Linux kernel. Once again, these are somewhat compromised usability-wise by compilers lacking __typeof__ support. Signed-off-by: Eric Wong <e@80x24.org> Reviewed-by: Derrick Stolee <stolee@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
939af16eac
commit
87571c3f71
@ -222,10 +222,11 @@ int cmd__hashmap(int argc, const char **argv)
|
||||
free(entry);
|
||||
|
||||
} else if (!strcmp("iterate", cmd)) {
|
||||
|
||||
struct hashmap_iter iter;
|
||||
hashmap_iter_init(&map, &iter);
|
||||
while ((entry = hashmap_iter_next(&iter)))
|
||||
|
||||
hashmap_for_each_entry(&map, &iter, entry,
|
||||
struct test_entry,
|
||||
ent /* member name */)
|
||||
printf("%s %s\n", entry->key, get_value(entry));
|
||||
|
||||
} else if (!strcmp("size", cmd)) {
|
||||
|
Reference in New Issue
Block a user