diff options
| author | Carson Fleming <[email protected]> | 2026-02-01 04:09:19 -0500 |
|---|---|---|
| committer | Carson Fleming <[email protected]> | 2026-02-01 04:09:19 -0500 |
| commit | 1ab4f55dfa898b0929bbb3c5ead76337b920d0bf (patch) | |
| tree | 2396e550b2517e6bfa202961c0b4d749163634fa /map.c | |
| parent | cbcbbc4c25126fae22369286eef75b3b0973d6ec (diff) | |
| download | safec-1ab4f55dfa898b0929bbb3c5ead76337b920d0bf.tar.gz | |
map_foreach + fix counter bug
Diffstat (limited to 'map.c')
| -rw-r--r-- | map.c | 11 |
1 files changed, 11 insertions, 0 deletions
@@ -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; + } + } +} |
