]>
Commit | Line | Data |
---|---|---|
4a280a7e LP |
1 | #pragma once |
2 | ||
3 | /*** | |
4 | This file is part of systemd. | |
5 | ||
6 | Copyright 2015 Lennart Poettering | |
7 | ||
8 | systemd is free software; you can redistribute it and/or modify it | |
9 | under the terms of the GNU Lesser General Public License as published by | |
10 | the Free Software Foundation; either version 2.1 of the License, or | |
11 | (at your option) any later version. | |
12 | ||
13 | systemd is distributed in the hope that it will be useful, but | |
14 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 | Lesser General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU Lesser General Public License | |
19 | along with systemd; If not, see <http://www.gnu.org/licenses/>. | |
20 | ***/ | |
21 | ||
22 | #include "hashmap.h" | |
23 | ||
24 | typedef struct OrderedSet OrderedSet; | |
25 | ||
26 | static inline OrderedSet* ordered_set_new(const struct hash_ops *ops) { | |
27 | return (OrderedSet*) ordered_hashmap_new(ops); | |
28 | } | |
29 | ||
0264d072 LP |
30 | static inline int ordered_set_ensure_allocated(OrderedSet **s, const struct hash_ops *ops) { |
31 | if (*s) | |
32 | return 0; | |
33 | ||
34 | *s = ordered_set_new(ops); | |
35 | if (!*s) | |
36 | return -ENOMEM; | |
37 | ||
38 | return 0; | |
39 | } | |
40 | ||
4a280a7e LP |
41 | static inline OrderedSet* ordered_set_free(OrderedSet *s) { |
42 | ordered_hashmap_free((OrderedHashmap*) s); | |
43 | return NULL; | |
44 | } | |
45 | ||
46 | static inline OrderedSet* ordered_set_free_free(OrderedSet *s) { | |
47 | ordered_hashmap_free_free((OrderedHashmap*) s); | |
48 | return NULL; | |
49 | } | |
50 | ||
51 | static inline int ordered_set_put(OrderedSet *s, void *p) { | |
52 | return ordered_hashmap_put((OrderedHashmap*) s, p, p); | |
53 | } | |
54 | ||
55 | static inline bool ordered_set_isempty(OrderedSet *s) { | |
56 | return ordered_hashmap_isempty((OrderedHashmap*) s); | |
57 | } | |
58 | ||
8927b1da DH |
59 | static inline bool ordered_set_iterate(OrderedSet *s, Iterator *i, void **value) { |
60 | return ordered_hashmap_iterate((OrderedHashmap*) s, i, value, NULL); | |
4a280a7e LP |
61 | } |
62 | ||
00616955 LP |
63 | int ordered_set_consume(OrderedSet *s, void *p); |
64 | int ordered_set_put_strdup(OrderedSet *s, const char *p); | |
65 | int ordered_set_put_strdupv(OrderedSet *s, char **l); | |
66 | ||
4a280a7e | 67 | #define ORDERED_SET_FOREACH(e, s, i) \ |
8927b1da | 68 | for ((i) = ITERATOR_FIRST; ordered_set_iterate((s), &(i), (void**)&(e)); ) |
4a280a7e LP |
69 | |
70 | DEFINE_TRIVIAL_CLEANUP_FUNC(OrderedSet*, ordered_set_free); | |
00616955 | 71 | DEFINE_TRIVIAL_CLEANUP_FUNC(OrderedSet*, ordered_set_free_free); |
4a280a7e LP |
72 | |
73 | #define _cleanup_ordered_set_free_ _cleanup_(ordered_set_freep) | |
00616955 | 74 | #define _cleanup_ordered_set_free_free_ _cleanup_(ordered_set_free_freep) |