summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2022-12-24 02:43:41 +0100
committerThomas Voss <mail@thomasvoss.com> 2022-12-24 02:52:25 +0100
commit6dc60bf49d2c43c701c6f578711d91e51dacb9cf (patch)
tree8d7fd630b076eca04c365a3081651604d3b74291 /examples
parenta5d1c6da7e5617c15dd729a7907fb38cc25c2e1b (diff)
Add the FOREACH and FOREACH_SAFE macros
Diffstat (limited to 'examples')
-rw-r--r--examples/gehashmap.c16
1 files changed, 16 insertions, 0 deletions
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);
}