util-lib: add ordered_set_ensure_allocated()

ordered_set_ensure_allocated() does for an OrderedSet, what
set_ensure_allicated() does for a Set.
This commit is contained in:
Lennart Poettering 2015-11-24 21:54:22 +01:00
parent eed857b717
commit 0264d0726f
2 changed files with 11 additions and 1 deletions

View file

@ -29,6 +29,17 @@ static inline OrderedSet* ordered_set_new(const struct hash_ops *ops) {
return (OrderedSet*) ordered_hashmap_new(ops);
}
static inline int ordered_set_ensure_allocated(OrderedSet **s, const struct hash_ops *ops) {
if (*s)
return 0;
*s = ordered_set_new(ops);
if (!*s)
return -ENOMEM;
return 0;
}
static inline OrderedSet* ordered_set_free(OrderedSet *s) {
ordered_hashmap_free((OrderedHashmap*) s);
return NULL;

View file

@ -27,7 +27,6 @@
Set *internal_set_new(const struct hash_ops *hash_ops HASHMAP_DEBUG_PARAMS);
#define set_new(ops) internal_set_new(ops HASHMAP_DEBUG_SRC_ARGS)
static inline Set *set_free(Set *s) {
internal_hashmap_free(HASHMAP_BASE(s));
return NULL;