1 /*-*- Mode: C; c-basic-offset: 8 -*-*/
4 This file is part of systemd.
6 Copyright 2010 Lennart Poettering
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
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 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
27 #define MAKE_SET(h) ((Set*) (h))
28 #define MAKE_HASHMAP(s) ((Hashmap*) (s))
30 /* For now this is not much more than a wrapper around a hashmap */
32 Set
*set_new(hash_func_t hash_func
, compare_func_t compare_func
) {
33 return MAKE_SET(hashmap_new(hash_func
, compare_func
));
36 void set_free(Set
* s
) {
37 hashmap_free(MAKE_HASHMAP(s
));
40 void set_free_free(Set
*s
) {
43 while ((p
= set_steal_first(s
)))
49 int set_ensure_allocated(Set
**s
, hash_func_t hash_func
, compare_func_t compare_func
) {
50 return hashmap_ensure_allocated((Hashmap
**) s
, hash_func
, compare_func
);
53 int set_put(Set
*s
, void *value
) {
54 return hashmap_put(MAKE_HASHMAP(s
), value
, value
);
57 int set_replace(Set
*s
, void *value
) {
58 return hashmap_replace(MAKE_HASHMAP(s
), value
, value
);
61 void *set_get(Set
*s
, void *value
) {
62 return hashmap_get(MAKE_HASHMAP(s
), value
);
65 void *set_remove(Set
*s
, void *value
) {
66 return hashmap_remove(MAKE_HASHMAP(s
), value
);
69 int set_remove_and_put(Set
*s
, void *old_value
, void *new_value
) {
70 return hashmap_remove_and_put(MAKE_HASHMAP(s
), old_value
, new_value
, new_value
);
73 unsigned set_size(Set
*s
) {
74 return hashmap_size(MAKE_HASHMAP(s
));
77 bool set_isempty(Set
*s
) {
78 return hashmap_isempty(MAKE_HASHMAP(s
));
81 void *set_iterate(Set
*s
, Iterator
*i
) {
82 return hashmap_iterate(MAKE_HASHMAP(s
), i
, NULL
);
85 void *set_iterate_backwards(Set
*s
, Iterator
*i
) {
86 return hashmap_iterate_backwards(MAKE_HASHMAP(s
), i
, NULL
);
89 void *set_iterate_skip(Set
*s
, void *value
, Iterator
*i
) {
90 return hashmap_iterate_skip(MAKE_HASHMAP(s
), value
, i
);
93 void *set_steal_first(Set
*s
) {
94 return hashmap_steal_first(MAKE_HASHMAP(s
));
97 void* set_first(Set
*s
) {
98 return hashmap_first(MAKE_HASHMAP(s
));
101 void* set_last(Set
*s
) {
102 return hashmap_last(MAKE_HASHMAP(s
));
105 int set_merge(Set
*s
, Set
*other
) {
106 return hashmap_merge(MAKE_HASHMAP(s
), MAKE_HASHMAP(other
));
109 void set_move(Set
*s
, Set
*other
) {
110 return hashmap_move(MAKE_HASHMAP(s
), MAKE_HASHMAP(other
));
113 int set_move_one(Set
*s
, Set
*other
, void *value
) {
114 return hashmap_move_one(MAKE_HASHMAP(s
), MAKE_HASHMAP(other
), value
);
117 Set
* set_copy(Set
*s
) {
118 return MAKE_SET(hashmap_copy(MAKE_HASHMAP(s
)));
121 void set_clear(Set
*s
) {
122 hashmap_clear(MAKE_HASHMAP(s
));