]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/basic/ordered-set.h
6c617ab3055eb02607a852c5f51e0a9b112ace64
[thirdparty/systemd.git] / src / basic / ordered-set.h
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3 #pragma once
4
5 /***
6 This file is part of systemd.
7
8 Copyright 2015 Lennart Poettering
9
10 systemd is free software; you can redistribute it and/or modify it
11 under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14
15 systemd is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
19
20 You should have received a copy of the GNU Lesser General Public License
21 along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 ***/
23
24 #include "hashmap.h"
25
26 typedef struct OrderedSet OrderedSet;
27
28 static inline OrderedSet* ordered_set_new(const struct hash_ops *ops) {
29 return (OrderedSet*) ordered_hashmap_new(ops);
30 }
31
32 static inline OrderedSet* ordered_set_free(OrderedSet *s) {
33 ordered_hashmap_free((OrderedHashmap*) s);
34 return NULL;
35 }
36
37 static inline OrderedSet* ordered_set_free_free(OrderedSet *s) {
38 ordered_hashmap_free_free((OrderedHashmap*) s);
39 return NULL;
40 }
41
42 static inline int ordered_set_put(OrderedSet *s, void *p) {
43 return ordered_hashmap_put((OrderedHashmap*) s, p, p);
44 }
45
46 static inline bool ordered_set_isempty(OrderedSet *s) {
47 return ordered_hashmap_isempty((OrderedHashmap*) s);
48 }
49
50 static inline bool ordered_set_iterate(OrderedSet *s, Iterator *i, void **value) {
51 return ordered_hashmap_iterate((OrderedHashmap*) s, i, value, NULL);
52 }
53
54 #define ORDERED_SET_FOREACH(e, s, i) \
55 for ((i) = ITERATOR_FIRST; ordered_set_iterate((s), &(i), (void**)&(e)); )
56
57 DEFINE_TRIVIAL_CLEANUP_FUNC(OrderedSet*, ordered_set_free);
58
59 #define _cleanup_ordered_set_free_ _cleanup_(ordered_set_freep)