From 6dc60bf49d2c43c701c6f578711d91e51dacb9cf Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Sat, 24 Dec 2022 02:43:41 +0100 Subject: Add the FOREACH and FOREACH_SAFE macros --- examples/gehashmap.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'examples') diff --git a/examples/gehashmap.c b/examples/gehashmap.c index 1ddd391..df91669 100644 --- a/examples/gehashmap.c +++ b/examples/gehashmap.c @@ -56,6 +56,7 @@ main(void) { int i; unsigned int u; + struct atoimap_entry *entry, *tmp; atoimap_t *map_a; itoumap_t *map_b; @@ -69,6 +70,11 @@ main(void) atoimap_get(map_a, "THOMAS VOẞ", &i); printf("THOMAS VOẞ -> %d\n", i); atoimap_get(map_a, "Thomas Voss", &i); printf("Thomas Voss -> %d\n", i); + GEHASHMAP_FOREACH_SAFE(entry, tmp, map_a) + atoimap_remove(map_a, entry->key); + GEHASHMAP_FOREACH(entry, map_a) + puts(entry->key); + itoumap_set(map_b, -42, +42); itoumap_set(map_b, -69, +69); itoumap_set(map_b, -420, +420); @@ -92,6 +98,16 @@ main(void) atoimap_free(map_a); itoumap_free(map_b); + atoimap_new(map_a); + atoimap_set(map_a, strdup("Thomas Voß"), 5); + atoimap_set(map_a, strdup("THOMAS VOẞ"), 6); + atoimap_set(map_a, strdup("Thomas Voss"), 7); + + GEHASHMAP_FOREACH(entry, map_a) + free(entry->key); + + atoimap_free(map_a); + free(map_a); free(map_b); } -- cgit v1.2.3