]>
Commit | Line | Data |
---|---|---|
d6c9574f | 1 | /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ |
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 | ||
60918275 LP |
22 | #include <stdlib.h> |
23 | ||
24 | #include "set.h" | |
25 | #include "hashmap.h" | |
26 | ||
27 | #define MAKE_SET(h) ((Set*) (h)) | |
28 | #define MAKE_HASHMAP(s) ((Hashmap*) (s)) | |
29 | ||
30 | /* For now this is not much more than a wrapper around a hashmap */ | |
31 | ||
32 | Set *set_new(hash_func_t hash_func, compare_func_t compare_func) { | |
33 | return MAKE_SET(hashmap_new(hash_func, compare_func)); | |
34 | } | |
35 | ||
36 | void set_free(Set* s) { | |
37 | hashmap_free(MAKE_HASHMAP(s)); | |
38 | } | |
39 | ||
53ec43c6 | 40 | void set_free_free(Set *s) { |
449ddb2d | 41 | hashmap_free_free(MAKE_HASHMAP(s)); |
53ec43c6 LP |
42 | } |
43 | ||
034c6ed7 LP |
44 | int set_ensure_allocated(Set **s, hash_func_t hash_func, compare_func_t compare_func) { |
45 | return hashmap_ensure_allocated((Hashmap**) s, hash_func, compare_func); | |
46 | } | |
47 | ||
60918275 LP |
48 | int set_put(Set *s, void *value) { |
49 | return hashmap_put(MAKE_HASHMAP(s), value, value); | |
50 | } | |
51 | ||
ef42202a ZJS |
52 | int set_consume(Set *s, void *value) { |
53 | int r = set_put(s, value); | |
54 | if (r < 0) | |
55 | free(value); | |
56 | return r; | |
57 | } | |
58 | ||
f00b3eda LP |
59 | int set_replace(Set *s, void *value) { |
60 | return hashmap_replace(MAKE_HASHMAP(s), value, value); | |
61 | } | |
62 | ||
60918275 LP |
63 | void *set_get(Set *s, void *value) { |
64 | return hashmap_get(MAKE_HASHMAP(s), value); | |
65 | } | |
66 | ||
96342de6 LN |
67 | bool set_contains(Set *s, void *value) { |
68 | return hashmap_contains(MAKE_HASHMAP(s), value); | |
69 | } | |
70 | ||
60918275 LP |
71 | void *set_remove(Set *s, void *value) { |
72 | return hashmap_remove(MAKE_HASHMAP(s), value); | |
73 | } | |
74 | ||
101d8e63 LP |
75 | int set_remove_and_put(Set *s, void *old_value, void *new_value) { |
76 | return hashmap_remove_and_put(MAKE_HASHMAP(s), old_value, new_value, new_value); | |
77 | } | |
78 | ||
60918275 LP |
79 | unsigned set_size(Set *s) { |
80 | return hashmap_size(MAKE_HASHMAP(s)); | |
81 | } | |
82 | ||
83 | bool set_isempty(Set *s) { | |
84 | return hashmap_isempty(MAKE_HASHMAP(s)); | |
85 | } | |
86 | ||
034c6ed7 LP |
87 | void *set_iterate(Set *s, Iterator *i) { |
88 | return hashmap_iterate(MAKE_HASHMAP(s), i, NULL); | |
89 | } | |
90 | ||
91 | void *set_iterate_backwards(Set *s, Iterator *i) { | |
92 | return hashmap_iterate_backwards(MAKE_HASHMAP(s), i, NULL); | |
60918275 LP |
93 | } |
94 | ||
034c6ed7 LP |
95 | void *set_iterate_skip(Set *s, void *value, Iterator *i) { |
96 | return hashmap_iterate_skip(MAKE_HASHMAP(s), value, i); | |
60918275 LP |
97 | } |
98 | ||
99 | void *set_steal_first(Set *s) { | |
100 | return hashmap_steal_first(MAKE_HASHMAP(s)); | |
101 | } | |
102 | ||
103 | void* set_first(Set *s) { | |
104 | return hashmap_first(MAKE_HASHMAP(s)); | |
105 | } | |
106 | ||
107 | void* set_last(Set *s) { | |
108 | return hashmap_last(MAKE_HASHMAP(s)); | |
109 | } | |
91cdde8a LP |
110 | |
111 | int set_merge(Set *s, Set *other) { | |
112 | return hashmap_merge(MAKE_HASHMAP(s), MAKE_HASHMAP(other)); | |
113 | } | |
114 | ||
101d8e63 LP |
115 | void set_move(Set *s, Set *other) { |
116 | return hashmap_move(MAKE_HASHMAP(s), MAKE_HASHMAP(other)); | |
117 | } | |
118 | ||
119 | int set_move_one(Set *s, Set *other, void *value) { | |
120 | return hashmap_move_one(MAKE_HASHMAP(s), MAKE_HASHMAP(other), value); | |
121 | } | |
122 | ||
91cdde8a LP |
123 | Set* set_copy(Set *s) { |
124 | return MAKE_SET(hashmap_copy(MAKE_HASHMAP(s))); | |
125 | } | |
11dd41ce LP |
126 | |
127 | void set_clear(Set *s) { | |
128 | hashmap_clear(MAKE_HASHMAP(s)); | |
129 | } | |
9946996c LP |
130 | |
131 | void set_clear_free(Set *s) { | |
132 | hashmap_clear_free(MAKE_HASHMAP(s)); | |
133 | } | |
9590dfe7 LP |
134 | |
135 | char **set_get_strv(Set *s) { | |
136 | return hashmap_get_strv(MAKE_HASHMAP(s)); | |
137 | } |