]>
Commit | Line | Data |
---|---|---|
60918275 LP |
1 | /*-*- Mode: C; c-basic-offset: 8 -*-*/ |
2 | ||
3 | #ifdef HAVE_CONFIG_H | |
4 | #include <config.h> | |
5 | #endif | |
6 | ||
7 | #include <stdlib.h> | |
8 | ||
9 | #include "set.h" | |
10 | #include "hashmap.h" | |
11 | ||
12 | #define MAKE_SET(h) ((Set*) (h)) | |
13 | #define MAKE_HASHMAP(s) ((Hashmap*) (s)) | |
14 | ||
15 | /* For now this is not much more than a wrapper around a hashmap */ | |
16 | ||
17 | Set *set_new(hash_func_t hash_func, compare_func_t compare_func) { | |
18 | return MAKE_SET(hashmap_new(hash_func, compare_func)); | |
19 | } | |
20 | ||
21 | void set_free(Set* s) { | |
22 | hashmap_free(MAKE_HASHMAP(s)); | |
23 | } | |
24 | ||
034c6ed7 LP |
25 | int set_ensure_allocated(Set **s, hash_func_t hash_func, compare_func_t compare_func) { |
26 | return hashmap_ensure_allocated((Hashmap**) s, hash_func, compare_func); | |
27 | } | |
28 | ||
60918275 LP |
29 | int set_put(Set *s, void *value) { |
30 | return hashmap_put(MAKE_HASHMAP(s), value, value); | |
31 | } | |
32 | ||
f00b3eda LP |
33 | int set_replace(Set *s, void *value) { |
34 | return hashmap_replace(MAKE_HASHMAP(s), value, value); | |
35 | } | |
36 | ||
60918275 LP |
37 | void *set_get(Set *s, void *value) { |
38 | return hashmap_get(MAKE_HASHMAP(s), value); | |
39 | } | |
40 | ||
41 | void *set_remove(Set *s, void *value) { | |
42 | return hashmap_remove(MAKE_HASHMAP(s), value); | |
43 | } | |
44 | ||
45 | unsigned set_size(Set *s) { | |
46 | return hashmap_size(MAKE_HASHMAP(s)); | |
47 | } | |
48 | ||
49 | bool set_isempty(Set *s) { | |
50 | return hashmap_isempty(MAKE_HASHMAP(s)); | |
51 | } | |
52 | ||
034c6ed7 LP |
53 | void *set_iterate(Set *s, Iterator *i) { |
54 | return hashmap_iterate(MAKE_HASHMAP(s), i, NULL); | |
55 | } | |
56 | ||
57 | void *set_iterate_backwards(Set *s, Iterator *i) { | |
58 | return hashmap_iterate_backwards(MAKE_HASHMAP(s), i, NULL); | |
60918275 LP |
59 | } |
60 | ||
034c6ed7 LP |
61 | void *set_iterate_skip(Set *s, void *value, Iterator *i) { |
62 | return hashmap_iterate_skip(MAKE_HASHMAP(s), value, i); | |
60918275 LP |
63 | } |
64 | ||
65 | void *set_steal_first(Set *s) { | |
66 | return hashmap_steal_first(MAKE_HASHMAP(s)); | |
67 | } | |
68 | ||
69 | void* set_first(Set *s) { | |
70 | return hashmap_first(MAKE_HASHMAP(s)); | |
71 | } | |
72 | ||
73 | void* set_last(Set *s) { | |
74 | return hashmap_last(MAKE_HASHMAP(s)); | |
75 | } | |
91cdde8a LP |
76 | |
77 | int set_merge(Set *s, Set *other) { | |
78 | return hashmap_merge(MAKE_HASHMAP(s), MAKE_HASHMAP(other)); | |
79 | } | |
80 | ||
81 | Set* set_copy(Set *s) { | |
82 | return MAKE_SET(hashmap_copy(MAKE_HASHMAP(s))); | |
83 | } | |
11dd41ce LP |
84 | |
85 | void set_clear(Set *s) { | |
86 | hashmap_clear(MAKE_HASHMAP(s)); | |
87 | } |