diff options
Diffstat (limited to 'utils/hashmap.c')
-rw-r--r-- | utils/hashmap.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/utils/hashmap.c b/utils/hashmap.c index 7ed19946b..bfbf6ceb8 100644 --- a/utils/hashmap.c +++ b/utils/hashmap.c @@ -213,3 +213,22 @@ hashmap_remove(hashmap_t *hashmap, void *key) return false; } + +/* Exported function, documented in hashmap.h */ +bool +hashmap_iterate(hashmap_t *hashmap, hashmap_iteration_cb_t cb, void *ctx) +{ + for (uint32_t bucket = 0; + bucket < hashmap->bucket_count; + bucket++) { + for (hashmap_entry_t *entry = hashmap->buckets[bucket]; + entry != NULL; + entry = entry->next) { + /* If the callback returns true, we early-exit */ + if (cb(entry->key, entry->value, ctx)) + return true; + } + } + + return false; +} |