summaryrefslogtreecommitdiff
path: root/map.c
diff options
context:
space:
mode:
authorCarson Fleming <[email protected]>2026-02-01 04:09:19 -0500
committerCarson Fleming <[email protected]>2026-02-01 04:09:19 -0500
commit1ab4f55dfa898b0929bbb3c5ead76337b920d0bf (patch)
tree2396e550b2517e6bfa202961c0b4d749163634fa /map.c
parentcbcbbc4c25126fae22369286eef75b3b0973d6ec (diff)
downloadsafec-1ab4f55dfa898b0929bbb3c5ead76337b920d0bf.tar.gz
map_foreach + fix counter bug
Diffstat (limited to 'map.c')
-rw-r--r--map.c11
1 files changed, 11 insertions, 0 deletions
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;
+ }
+ }
+}