From 1ab4f55dfa898b0929bbb3c5ead76337b920d0bf Mon Sep 17 00:00:00 2001 From: Carson Fleming Date: Sun, 1 Feb 2026 04:09:19 -0500 Subject: map_foreach + fix counter bug --- map.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'map.c') diff --git a/map.c b/map.c index ab7f922..a34def4 100644 --- a/map.c +++ b/map.c @@ -156,9 +156,20 @@ void* map_remove(map_t* map, const void* key) { struct __map_entry* entry = fetch_entry(map, key); if (entry->next == NULL) return NULL; + map->size--; void* rv = entry->value; struct __map_entry* steal = entry->next; *entry = *steal; free(steal); return rv; } + +void map_foreach(map_t* map, foreach_func_t foreach_func, void* data) { + for (size_t i = 0; i < map->__num_buckets; i++) { + struct __map_entry* entry = &map->__buckets[i]; + while (entry->next != NULL) { + foreach_func(entry->key, entry->value, data); + entry = entry->next; + } + } +} -- cgit v1.2.3