summaryrefslogtreecommitdiff
path: root/src/basic/set.h
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2017-11-28 12:35:49 +0100
committerSven Eden <yamakuzure@gmx.net>2017-11-28 12:35:49 +0100
commit6c66e1744f4b338d6b2f003920356d63bc6259f3 (patch)
treef29ad59ac6bf74b0a3c6fe3675e3525d7ee557af /src/basic/set.h
parent84dc26bac24fa3a916147d375d28f8bc41e7b3b5 (diff)
Add set/hashmap helpers for non-trivial freeing and use where straighforward
A macro is needed because otherwise we couldn't ensure type safety. Some simple tests are included. No functional change intended.
Diffstat (limited to 'src/basic/set.h')
-rw-r--r--src/basic/set.h12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/basic/set.h b/src/basic/set.h
index 08b7c4a72..b424f3423 100644
--- a/src/basic/set.h
+++ b/src/basic/set.h
@@ -109,6 +109,18 @@ static inline void *set_steal_first(Set *s) {
return internal_hashmap_steal_first(HASHMAP_BASE(s));
}
+#define set_clear_with_destructor(_s, _f) \
+ ({ \
+ void *_item; \
+ while ((_item = set_steal_first(_s))) \
+ _f(_item); \
+ })
+#define set_free_with_destructor(_s, _f) \
+ ({ \
+ set_clear_with_destructor(_s, _f); \
+ set_free(_s); \
+ })
+
/* no set_steal_first_key */
/* no set_first_key */