]>
Commit | Line | Data |
---|---|---|
c2f1db8f | 1 | #pragma once |
60918275 | 2 | |
a7334b09 LP |
3 | /*** |
4 | This file is part of systemd. | |
5 | ||
6 | Copyright 2010 Lennart Poettering | |
7 | ||
8 | systemd is free software; you can redistribute it and/or modify it | |
5430f7f2 LP |
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 | |
a7334b09 LP |
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 | |
5430f7f2 | 16 | Lesser General Public License for more details. |
a7334b09 | 17 | |
5430f7f2 | 18 | You should have received a copy of the GNU Lesser General Public License |
a7334b09 LP |
19 | along with systemd; If not, see <http://www.gnu.org/licenses/>. |
20 | ***/ | |
21 | ||
d97c5aea | 22 | #include "extract-word.h" |
60918275 | 23 | #include "hashmap.h" |
a2341f68 | 24 | #include "macro.h" |
60918275 | 25 | |
163f561e ZJS |
26 | Set *internal_set_new(const struct hash_ops *hash_ops HASHMAP_DEBUG_PARAMS); |
27 | #define set_new(ops) internal_set_new(ops HASHMAP_DEBUG_SRC_ARGS) | |
60918275 | 28 | |
bd9f2fc2 | 29 | static inline Set *set_free(Set *s) { |
89439d4f | 30 | internal_hashmap_free(HASHMAP_BASE(s)); |
bd9f2fc2 | 31 | return NULL; |
89439d4f | 32 | } |
60918275 | 33 | |
bd9f2fc2 | 34 | static inline Set *set_free_free(Set *s) { |
89439d4f | 35 | internal_hashmap_free_free(HASHMAP_BASE(s)); |
bd9f2fc2 | 36 | return NULL; |
89439d4f MS |
37 | } |
38 | ||
39 | /* no set_free_free_free */ | |
40 | ||
41 | static inline Set *set_copy(Set *s) { | |
42 | return (Set*) internal_hashmap_copy(HASHMAP_BASE(s)); | |
43 | } | |
44 | ||
163f561e ZJS |
45 | int internal_set_ensure_allocated(Set **s, const struct hash_ops *hash_ops HASHMAP_DEBUG_PARAMS); |
46 | #define set_ensure_allocated(h, ops) internal_set_ensure_allocated(h, ops HASHMAP_DEBUG_SRC_ARGS) | |
60918275 | 47 | |
89439d4f MS |
48 | int set_put(Set *s, const void *key); |
49 | /* no set_update */ | |
50 | /* no set_replace */ | |
51 | static inline void *set_get(Set *s, void *key) { | |
52 | return internal_hashmap_get(HASHMAP_BASE(s), key); | |
53 | } | |
54 | /* no set_get2 */ | |
55 | ||
56 | static inline bool set_contains(Set *s, const void *key) { | |
57 | return internal_hashmap_contains(HASHMAP_BASE(s), key); | |
58 | } | |
59 | ||
4a9185c4 | 60 | static inline void *set_remove(Set *s, const void *key) { |
89439d4f MS |
61 | return internal_hashmap_remove(HASHMAP_BASE(s), key); |
62 | } | |
63 | ||
64 | /* no set_remove2 */ | |
65 | /* no set_remove_value */ | |
66 | int set_remove_and_put(Set *s, const void *old_key, const void *new_key); | |
67 | /* no set_remove_and_replace */ | |
91cdde8a LP |
68 | int set_merge(Set *s, Set *other); |
69 | ||
89439d4f MS |
70 | static inline int set_reserve(Set *h, unsigned entries_add) { |
71 | return internal_hashmap_reserve(HASHMAP_BASE(h), entries_add); | |
72 | } | |
73 | ||
74 | static inline int set_move(Set *s, Set *other) { | |
75 | return internal_hashmap_move(HASHMAP_BASE(s), HASHMAP_BASE(other)); | |
76 | } | |
77 | ||
78 | static inline int set_move_one(Set *s, Set *other, const void *key) { | |
79 | return internal_hashmap_move_one(HASHMAP_BASE(s), HASHMAP_BASE(other), key); | |
80 | } | |
81 | ||
82 | static inline unsigned set_size(Set *s) { | |
83 | return internal_hashmap_size(HASHMAP_BASE(s)); | |
84 | } | |
85 | ||
86 | static inline bool set_isempty(Set *s) { | |
87 | return set_size(s) == 0; | |
88 | } | |
89 | ||
90 | static inline unsigned set_buckets(Set *s) { | |
91 | return internal_hashmap_buckets(HASHMAP_BASE(s)); | |
92 | } | |
60918275 | 93 | |
8927b1da | 94 | bool set_iterate(Set *s, Iterator *i, void **value); |
60918275 | 95 | |
89439d4f MS |
96 | static inline void set_clear(Set *s) { |
97 | internal_hashmap_clear(HASHMAP_BASE(s)); | |
98 | } | |
99 | ||
100 | static inline void set_clear_free(Set *s) { | |
101 | internal_hashmap_clear_free(HASHMAP_BASE(s)); | |
102 | } | |
103 | ||
104 | /* no set_clear_free_free */ | |
105 | ||
106 | static inline void *set_steal_first(Set *s) { | |
107 | return internal_hashmap_steal_first(HASHMAP_BASE(s)); | |
108 | } | |
109 | ||
110 | /* no set_steal_first_key */ | |
111 | /* no set_first_key */ | |
9946996c | 112 | |
89439d4f MS |
113 | static inline void *set_first(Set *s) { |
114 | return internal_hashmap_first(HASHMAP_BASE(s)); | |
115 | } | |
60918275 | 116 | |
89439d4f MS |
117 | /* no set_next */ |
118 | ||
119 | static inline char **set_get_strv(Set *s) { | |
120 | return internal_hashmap_get_strv(HASHMAP_BASE(s)); | |
121 | } | |
122 | ||
123 | int set_consume(Set *s, void *value); | |
124 | int set_put_strdup(Set *s, const char *p); | |
125 | int set_put_strdupv(Set *s, char **l); | |
d97c5aea | 126 | int set_put_strsplit(Set *s, const char *v, const char *separators, ExtractFlags flags); |
9590dfe7 | 127 | |
034c6ed7 | 128 | #define SET_FOREACH(e, s, i) \ |
8927b1da | 129 | for ((i) = ITERATOR_FIRST; set_iterate((s), &(i), (void**)&(e)); ) |
60918275 | 130 | |
35aa04e9 LP |
131 | #define SET_FOREACH_MOVE(e, d, s) \ |
132 | for (; ({ e = set_first(s); assert_se(!e || set_move_one(d, s, e) >= 0); e; }); ) | |
133 | ||
14bf2c9d LP |
134 | DEFINE_TRIVIAL_CLEANUP_FUNC(Set*, set_free); |
135 | DEFINE_TRIVIAL_CLEANUP_FUNC(Set*, set_free_free); | |
89439d4f | 136 | |
dfb33a97 LP |
137 | #define _cleanup_set_free_ _cleanup_(set_freep) |
138 | #define _cleanup_set_free_free_ _cleanup_(set_free_freep) |