Merge pull request #18989 from yuwata/ordered-set-put-strdup
ordered-set: make ordered_set_put_strdup() allocate OrderedSet object
This commit is contained in:
+12
-9
@@ -35,30 +35,33 @@ int ordered_set_consume(OrderedSet *s, void *p) {
|
||||
return r;
|
||||
}
|
||||
|
||||
int ordered_set_put_strdup(OrderedSet *s, const char *p) {
|
||||
int _ordered_set_put_strdup(OrderedSet **s, const char *p HASHMAP_DEBUG_PARAMS) {
|
||||
char *c;
|
||||
int r;
|
||||
|
||||
assert(s);
|
||||
assert(p);
|
||||
|
||||
r = _ordered_set_ensure_allocated(s, &string_hash_ops_free HASHMAP_DEBUG_PASS_ARGS);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (ordered_set_contains(*s, p))
|
||||
return 0;
|
||||
|
||||
c = strdup(p);
|
||||
if (!c)
|
||||
return -ENOMEM;
|
||||
|
||||
r = ordered_set_consume(s, c);
|
||||
if (r == -EEXIST)
|
||||
return 0;
|
||||
|
||||
return r;
|
||||
return ordered_set_consume(*s, c);
|
||||
}
|
||||
|
||||
int ordered_set_put_strdupv(OrderedSet *s, char **l) {
|
||||
int _ordered_set_put_strdupv(OrderedSet **s, char **l HASHMAP_DEBUG_PARAMS) {
|
||||
int n = 0, r;
|
||||
char **i;
|
||||
|
||||
STRV_FOREACH(i, l) {
|
||||
r = ordered_set_put_strdup(s, *i);
|
||||
r = _ordered_set_put_strdup(s, *i HASHMAP_DEBUG_PASS_ARGS);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@@ -68,7 +71,7 @@ int ordered_set_put_strdupv(OrderedSet *s, char **l) {
|
||||
return n;
|
||||
}
|
||||
|
||||
int ordered_set_put_string_set(OrderedSet *s, OrderedSet *l) {
|
||||
int ordered_set_put_string_set(OrderedSet **s, OrderedSet *l) {
|
||||
int n = 0, r;
|
||||
char *p;
|
||||
|
||||
|
||||
@@ -26,6 +26,10 @@ static inline OrderedSet* ordered_set_free_free(OrderedSet *s) {
|
||||
return (OrderedSet*) ordered_hashmap_free_free((OrderedHashmap*) s);
|
||||
}
|
||||
|
||||
static inline int ordered_set_contains(OrderedSet *s, const void *p) {
|
||||
return ordered_hashmap_contains((OrderedHashmap*) s, p);
|
||||
}
|
||||
|
||||
static inline int ordered_set_put(OrderedSet *s, void *p) {
|
||||
return ordered_hashmap_put((OrderedHashmap*) s, p, p);
|
||||
}
|
||||
@@ -59,9 +63,11 @@ static inline char** ordered_set_get_strv(OrderedSet *s) {
|
||||
}
|
||||
|
||||
int ordered_set_consume(OrderedSet *s, void *p);
|
||||
int ordered_set_put_strdup(OrderedSet *s, const char *p);
|
||||
int ordered_set_put_strdupv(OrderedSet *s, char **l);
|
||||
int ordered_set_put_string_set(OrderedSet *s, OrderedSet *l);
|
||||
int _ordered_set_put_strdup(OrderedSet **s, const char *p HASHMAP_DEBUG_PARAMS);
|
||||
#define ordered_set_put_strdup(s, p) _ordered_set_put_strdup(s, p HASHMAP_DEBUG_SRC_ARGS)
|
||||
int _ordered_set_put_strdupv(OrderedSet **s, char **l HASHMAP_DEBUG_PARAMS);
|
||||
#define ordered_set_put_strdupv(s, l) _ordered_set_put_strdupv(s, l HASHMAP_DEBUG_SRC_ARGS)
|
||||
int ordered_set_put_string_set(OrderedSet **s, OrderedSet *l);
|
||||
void ordered_set_print(FILE *f, const char *field, OrderedSet *s);
|
||||
|
||||
#define _ORDERED_SET_FOREACH(e, s, i) \
|
||||
|
||||
Reference in New Issue
Block a user