summaryrefslogtreecommitdiff
path: root/utils/hashmap.h
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.h
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.h')
-rw-r--r--utils/hashmap.h22
1 files changed, 22 insertions, 0 deletions
diff --git a/utils/hashmap.h b/utils/hashmap.h
index 462b51ed2..cb8fd5074 100644
--- a/utils/hashmap.h
+++ b/utils/hashmap.h
@@ -62,6 +62,16 @@ typedef void* (*hashmap_value_alloc_t)(void *);
typedef void (*hashmap_value_destroy_t)(void *);
/**
+ * Hashmap iteration callback function type.
+ *
+ * First parameter is the key, second is the value.
+ * The final parameter is the context pointer for the iteration.
+ *
+ * Return true to stop iterating early
+ */
+typedef bool (*hashmap_iteration_cb_t)(void *, void *, void *);
+
+/**
* Parameters for hashmaps
*/
typedef struct {
@@ -163,5 +173,17 @@ void *hashmap_insert(hashmap_t *hashmap, void *key);
*/
bool hashmap_remove(hashmap_t *hashmap, void *key);
+/**
+ * Iterate the hashmap
+ *
+ * For each key/value pair in the hashmap, call the callback passing in
+ * the key and value. During iteration you MUST NOT mutate the hashmap.
+ *
+ * \param hashmap The hashmap to iterate
+ * \param cb The callback for each key,value pair
+ * \param ctx The callback context
+ * \return Whether or not we stopped iteration early
+ */
+bool hashmap_iterate(hashmap_t *hashmap, hashmap_iteration_cb_t cb, void *ctx);
#endif