summaryrefslogtreecommitdiff
path: root/utils/hashmap.c
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2020-02-23 16:46:22 +0000
committerDaniel Silverstone <dsilvers@digital-scurf.org>2020-02-23 20:59:39 +0000
commit54b1960d18042cf6dfd86cfe01d58455357586d2 (patch)
tree42286b7f107b465780cdaaa0532d2f2b8b8e5072 /utils/hashmap.c
parentfd80341513813684ba3155b87e4e6cc8c87631f1 (diff)
downloadnetsurf-54b1960d18042cf6dfd86cfe01d58455357586d2.tar.gz
netsurf-54b1960d18042cf6dfd86cfe01d58455357586d2.tar.bz2
utils: Add iteration API to hashmap
Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
Diffstat (limited to 'utils/hashmap.c')
-rw-r--r--utils/hashmap.c19
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;
+}