1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
4 #include "ordered-set.h"
7 int _ordered_set_ensure_allocated(OrderedSet
**s
, const struct hash_ops
*ops HASHMAP_DEBUG_PARAMS
) {
11 *s
= _ordered_set_new(ops HASHMAP_DEBUG_PASS_ARGS
);
18 int _ordered_set_ensure_put(OrderedSet
**s
, const struct hash_ops
*ops
, void *p HASHMAP_DEBUG_PARAMS
) {
21 r
= _ordered_set_ensure_allocated(s
, ops HASHMAP_DEBUG_PASS_ARGS
);
25 return ordered_set_put(*s
, p
);
28 int ordered_set_consume(OrderedSet
*s
, void *p
) {
31 r
= ordered_set_put(s
, p
);
38 int _ordered_set_put_strdup(OrderedSet
**s
, const char *p HASHMAP_DEBUG_PARAMS
) {
45 r
= _ordered_set_ensure_allocated(s
, &string_hash_ops_free HASHMAP_DEBUG_PASS_ARGS
);
49 if (ordered_set_contains(*s
, p
))
56 return ordered_set_consume(*s
, c
);
59 int _ordered_set_put_strdupv(OrderedSet
**s
, char **l HASHMAP_DEBUG_PARAMS
) {
64 r
= _ordered_set_put_strdup(s
, *i HASHMAP_DEBUG_PASS_ARGS
);
74 int ordered_set_put_string_set(OrderedSet
**s
, OrderedSet
*l
) {
78 /* Like ordered_set_put_strv, but for an OrderedSet of strings */
80 ORDERED_SET_FOREACH(p
, l
) {
81 r
= ordered_set_put_strdup(s
, p
);
91 void ordered_set_print(FILE *f
, const char *field
, OrderedSet
*s
) {
95 if (ordered_set_isempty(s
))
100 ORDERED_SET_FOREACH(p
, s
)
101 fputs_with_space(f
, p
, NULL
, &space
);