• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

systemd / systemd / 14481768866

15 Apr 2025 11:30PM UTC coverage: 72.112% (+0.08%) from 72.031%
14481768866

push

github

yuwata
docs: fix mkosi section for Environment= setting

297023 of 411890 relevant lines covered (72.11%)

685615.48 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

98.21
/src/basic/hashmap.h
1
/* SPDX-License-Identifier: LGPL-2.1-or-later */
2
#pragma once
3

4
#include <limits.h>
5
#include <stdbool.h>
6
#include <stddef.h>
7

8
#include "hash-funcs.h"
9
#include "macro.h"
10

11
/*
12
 * A hash table implementation. As a minor optimization a NULL hashmap object
13
 * will be treated as empty hashmap for all read operations. That way it is not
14
 * necessary to instantiate an object for each Hashmap use.
15
 *
16
 * If ENABLE_DEBUG_HASHMAP is defined (by configuring with -Ddebug-extra=hashmap),
17
 * the implementation will:
18
 * - store extra data for debugging and statistics (see tools/gdb-sd_dump_hashmaps.py)
19
 * - perform extra checks for invalid use of iterators
20
 */
21

22
#define HASH_KEY_SIZE 16
23

24
typedef void* (*hashmap_destroy_t)(void *p);
25

26
/* The base type for all hashmap and set types. Many functions in the implementation take (HashmapBase*)
27
 * parameters and are run-time polymorphic, though the API is not meant to be polymorphic (do not call
28
 * underscore-prefixed functions directly). */
29
typedef struct HashmapBase HashmapBase;
30

31
/* Specific hashmap/set types */
32
typedef struct Hashmap Hashmap;               /* Maps keys to values */
33
typedef struct OrderedHashmap OrderedHashmap; /* Like Hashmap, but also remembers entry insertion order */
34
typedef struct Set Set;                       /* Stores just keys */
35

36
typedef struct IteratedCache IteratedCache;   /* Caches the iterated order of one of the above */
37

38
/* Ideally the Iterator would be an opaque struct, but it is instantiated
39
 * by hashmap users, so the definition has to be here. Do not use its fields
40
 * directly. */
41
typedef struct {
42
        const void *next_key; /* expected value of that entry's key pointer */
43
        unsigned idx;         /* index of an entry to be iterated next */
44
#if ENABLE_DEBUG_HASHMAP
45
        unsigned put_count;   /* hashmap's put_count recorded at start of iteration */
46
        unsigned rem_count;   /* hashmap's rem_count in previous iteration */
47
        unsigned prev_idx;    /* idx in previous iteration */
48
#endif
49
} Iterator;
50

51
#define _IDX_ITERATOR_FIRST (UINT_MAX - 1)
52
#define ITERATOR_FIRST ((Iterator) { .idx = _IDX_ITERATOR_FIRST, .next_key = NULL })
53
#define ITERATOR_IS_FIRST(i) ((i).idx == _IDX_ITERATOR_FIRST)
54

55
/* Macros for type checking */
56
#define PTR_COMPATIBLE_WITH_HASHMAP_BASE(h) \
57
        (__builtin_types_compatible_p(typeof(h), HashmapBase*) || \
58
         __builtin_types_compatible_p(typeof(h), Hashmap*) || \
59
         __builtin_types_compatible_p(typeof(h), OrderedHashmap*) || \
60
         __builtin_types_compatible_p(typeof(h), Set*))
61

62
#define PTR_COMPATIBLE_WITH_PLAIN_HASHMAP(h) \
63
        (__builtin_types_compatible_p(typeof(h), Hashmap*) || \
64
         __builtin_types_compatible_p(typeof(h), OrderedHashmap*)) \
65

66
#define HASHMAP_BASE(h) \
67
        __builtin_choose_expr(PTR_COMPATIBLE_WITH_HASHMAP_BASE(h), \
68
                (HashmapBase*)(h), \
69
                (void)0)
70

71
#define PLAIN_HASHMAP(h) \
72
        __builtin_choose_expr(PTR_COMPATIBLE_WITH_PLAIN_HASHMAP(h), \
73
                (Hashmap*)(h), \
74
                (void)0)
75

76
#if ENABLE_DEBUG_HASHMAP
77
# define HASHMAP_DEBUG_PARAMS , const char *func, const char *file, int line
78
# define HASHMAP_DEBUG_SRC_ARGS   , __func__, PROJECT_FILE, __LINE__
79
# define HASHMAP_DEBUG_PASS_ARGS   , func, file, line
80
#else
81
# define HASHMAP_DEBUG_PARAMS
82
# define HASHMAP_DEBUG_SRC_ARGS
83
# define HASHMAP_DEBUG_PASS_ARGS
84
#endif
85

86
Hashmap* _hashmap_new(const struct hash_ops *hash_ops  HASHMAP_DEBUG_PARAMS);
87
OrderedHashmap* _ordered_hashmap_new(const struct hash_ops *hash_ops  HASHMAP_DEBUG_PARAMS);
88
#define hashmap_new(ops) _hashmap_new(ops  HASHMAP_DEBUG_SRC_ARGS)
89
#define ordered_hashmap_new(ops) _ordered_hashmap_new(ops  HASHMAP_DEBUG_SRC_ARGS)
90

91
#define hashmap_free_and_replace(a, b)          \
92
        free_and_replace_full(a, b, hashmap_free)
93

94
HashmapBase* _hashmap_free(HashmapBase *h, free_func_t default_free_key, free_func_t default_free_value);
95
static inline Hashmap* hashmap_free(Hashmap *h) {
4,037,459✔
96
        return (void*) _hashmap_free(HASHMAP_BASE(h), NULL, NULL);
3,519,896✔
97
}
98
static inline OrderedHashmap* ordered_hashmap_free(OrderedHashmap *h) {
4,307,241✔
99
        return (void*) _hashmap_free(HASHMAP_BASE(h), NULL, NULL);
3,121,064✔
100
}
101

102
IteratedCache* iterated_cache_free(IteratedCache *cache);
103
int iterated_cache_get(IteratedCache *cache, const void ***res_keys, const void ***res_values, unsigned *res_n_entries);
104

105
HashmapBase* _hashmap_copy(HashmapBase *h  HASHMAP_DEBUG_PARAMS);
106
#define hashmap_copy(h) ((Hashmap*) _hashmap_copy(HASHMAP_BASE(h)  HASHMAP_DEBUG_SRC_ARGS))
107
#define ordered_hashmap_copy(h) ((OrderedHashmap*) _hashmap_copy(HASHMAP_BASE(h)  HASHMAP_DEBUG_SRC_ARGS))
108

109
int _hashmap_ensure_allocated(Hashmap **h, const struct hash_ops *hash_ops  HASHMAP_DEBUG_PARAMS);
110
int _hashmap_ensure_put(Hashmap **h, const struct hash_ops *hash_ops, const void *key, void *value  HASHMAP_DEBUG_PARAMS);
111
int _ordered_hashmap_ensure_allocated(OrderedHashmap **h, const struct hash_ops *hash_ops  HASHMAP_DEBUG_PARAMS);
112
int _hashmap_ensure_replace(Hashmap **h, const struct hash_ops *hash_ops, const void *key, void *value  HASHMAP_DEBUG_PARAMS);
113

114
#define hashmap_ensure_allocated(h, ops) _hashmap_ensure_allocated(h, ops  HASHMAP_DEBUG_SRC_ARGS)
115
#define hashmap_ensure_put(s, ops, key, value) _hashmap_ensure_put(s, ops, key, value  HASHMAP_DEBUG_SRC_ARGS)
116
#define ordered_hashmap_ensure_allocated(h, ops) _ordered_hashmap_ensure_allocated(h, ops  HASHMAP_DEBUG_SRC_ARGS)
117
#define hashmap_ensure_replace(s, ops, key, value) _hashmap_ensure_replace(s, ops, key, value  HASHMAP_DEBUG_SRC_ARGS)
118

119
int _ordered_hashmap_ensure_put(OrderedHashmap **h, const struct hash_ops *hash_ops, const void *key, void *value  HASHMAP_DEBUG_PARAMS);
120
#define ordered_hashmap_ensure_put(s, ops, key, value) _ordered_hashmap_ensure_put(s, ops, key, value  HASHMAP_DEBUG_SRC_ARGS)
121

122
int _ordered_hashmap_ensure_replace(OrderedHashmap **h, const struct hash_ops *hash_ops, const void *key, void *value  HASHMAP_DEBUG_PARAMS);
123
#define ordered_hashmap_ensure_replace(s, ops, key, value) _ordered_hashmap_ensure_replace(s, ops, key, value  HASHMAP_DEBUG_SRC_ARGS)
124

125
IteratedCache* _hashmap_iterated_cache_new(HashmapBase *h);
126
static inline IteratedCache* hashmap_iterated_cache_new(Hashmap *h) {
1✔
127
        return (IteratedCache*) _hashmap_iterated_cache_new(HASHMAP_BASE(h));
1✔
128
}
129
static inline IteratedCache* ordered_hashmap_iterated_cache_new(OrderedHashmap *h) {
6,276✔
130
        return (IteratedCache*) _hashmap_iterated_cache_new(HASHMAP_BASE(h));
6,276✔
131
}
132

133
int hashmap_put(Hashmap *h, const void *key, void *value);
134
static inline int ordered_hashmap_put(OrderedHashmap *h, const void *key, void *value) {
7,949,088✔
135
        return hashmap_put(PLAIN_HASHMAP(h), key, value);
7,949,063✔
136
}
137

138
int _hashmap_put_strdup_full(Hashmap **h, const struct hash_ops *hash_ops, const char *k, const char *v  HASHMAP_DEBUG_PARAMS);
139
#define hashmap_put_strdup_full(h, hash_ops, k, v) _hashmap_put_strdup_full(h, hash_ops, k, v  HASHMAP_DEBUG_SRC_ARGS)
140
#define hashmap_put_strdup(h, k, v) hashmap_put_strdup_full(h, &string_hash_ops_free_free, k, v)
141

142
int hashmap_update(Hashmap *h, const void *key, void *value);
143
static inline int ordered_hashmap_update(OrderedHashmap *h, const void *key, void *value) {
4✔
144
        return hashmap_update(PLAIN_HASHMAP(h), key, value);
4✔
145
}
146

147
int hashmap_replace(Hashmap *h, const void *key, void *value);
148
static inline int ordered_hashmap_replace(OrderedHashmap *h, const void *key, void *value) {
11,948,722✔
149
        return hashmap_replace(PLAIN_HASHMAP(h), key, value);
11,948,722✔
150
}
151

152
void* _hashmap_get(HashmapBase *h, const void *key);
153
static inline void *hashmap_get(Hashmap *h, const void *key) {
27,628,159✔
154
        return _hashmap_get(HASHMAP_BASE(h), key);
27,062,907✔
155
}
156
static inline void *ordered_hashmap_get(OrderedHashmap *h, const void *key) {
29,199,677✔
157
        return _hashmap_get(HASHMAP_BASE(h), key);
29,199,909✔
158
}
159

160
void* hashmap_get2(Hashmap *h, const void *key, void **rkey);
161
static inline void *ordered_hashmap_get2(OrderedHashmap *h, const void *key, void **rkey) {
11,940,944✔
162
        return hashmap_get2(PLAIN_HASHMAP(h), key, rkey);
11,940,944✔
163
}
164

165
bool _hashmap_contains(HashmapBase *h, const void *key);
166
static inline bool hashmap_contains(Hashmap *h, const void *key) {
1,238,436✔
167
        return _hashmap_contains(HASHMAP_BASE(h), key);
1,238,436✔
168
}
169
static inline bool ordered_hashmap_contains(OrderedHashmap *h, const void *key) {
18,663✔
170
        return _hashmap_contains(HASHMAP_BASE(h), key);
18,663✔
171
}
172

173
void* _hashmap_remove(HashmapBase *h, const void *key);
174
static inline void *hashmap_remove(Hashmap *h, const void *key) {
6,798,250✔
175
        return _hashmap_remove(HASHMAP_BASE(h), key);
6,794,509✔
176
}
177
static inline void *ordered_hashmap_remove(OrderedHashmap *h, const void *key) {
64,490✔
178
        return _hashmap_remove(HASHMAP_BASE(h), key);
64,490✔
179
}
180

181
void* hashmap_remove2(Hashmap *h, const void *key, void **rkey);
182
static inline void *ordered_hashmap_remove2(OrderedHashmap *h, const void *key, void **rkey) {
557,981✔
183
        return hashmap_remove2(PLAIN_HASHMAP(h), key, rkey);
557,981✔
184
}
185

186
void* _hashmap_remove_value(HashmapBase *h, const void *key, void *value);
187
static inline void *hashmap_remove_value(Hashmap *h, const void *key, void *value) {
351,054✔
188
        return _hashmap_remove_value(HASHMAP_BASE(h), key, value);
350,964✔
189
}
190

191
static inline void* ordered_hashmap_remove_value(OrderedHashmap *h, const void *key, void *value) {
93,269✔
192
        return hashmap_remove_value(PLAIN_HASHMAP(h), key, value);
93,269✔
193
}
194

195
int hashmap_remove_and_put(Hashmap *h, const void *old_key, const void *new_key, void *value);
196
static inline int ordered_hashmap_remove_and_put(OrderedHashmap *h, const void *old_key, const void *new_key, void *value) {
4✔
197
        return hashmap_remove_and_put(PLAIN_HASHMAP(h), old_key, new_key, value);
4✔
198
}
199

200
int hashmap_remove_and_replace(Hashmap *h, const void *old_key, const void *new_key, void *value);
201
static inline int ordered_hashmap_remove_and_replace(OrderedHashmap *h, const void *old_key, const void *new_key, void *value) {
24✔
202
        return hashmap_remove_and_replace(PLAIN_HASHMAP(h), old_key, new_key, value);
24✔
203
}
204

205
/* Since merging data from an OrderedHashmap into a Hashmap or vice-versa
206
 * should just work, allow this by having looser type-checking here. */
207
int _hashmap_merge(Hashmap *h, Hashmap *other);
208
#define hashmap_merge(h, other) _hashmap_merge(PLAIN_HASHMAP(h), PLAIN_HASHMAP(other))
209
#define ordered_hashmap_merge(h, other) hashmap_merge(h, other)
210

211
int _hashmap_reserve(HashmapBase *h, unsigned entries_add);
212
static inline int hashmap_reserve(Hashmap *h, unsigned entries_add) {
16✔
213
        return _hashmap_reserve(HASHMAP_BASE(h), entries_add);
16✔
214
}
215
static inline int ordered_hashmap_reserve(OrderedHashmap *h, unsigned entries_add) {
1,508✔
216
        return _hashmap_reserve(HASHMAP_BASE(h), entries_add);
1,508✔
217
}
218

219
int _hashmap_move(HashmapBase *h, HashmapBase *other);
220
/* Unlike hashmap_merge, hashmap_move does not allow mixing the types. */
221
static inline int hashmap_move(Hashmap *h, Hashmap *other) {
2,479✔
222
        return _hashmap_move(HASHMAP_BASE(h), HASHMAP_BASE(other));
2,479✔
223
}
224
static inline int ordered_hashmap_move(OrderedHashmap *h, OrderedHashmap *other) {
2✔
225
        return _hashmap_move(HASHMAP_BASE(h), HASHMAP_BASE(other));
2✔
226
}
227

228
int _hashmap_move_one(HashmapBase *h, HashmapBase *other, const void *key);
229
static inline int hashmap_move_one(Hashmap *h, Hashmap *other, const void *key) {
5✔
230
        return _hashmap_move_one(HASHMAP_BASE(h), HASHMAP_BASE(other), key);
5✔
231
}
232
static inline int ordered_hashmap_move_one(OrderedHashmap *h, OrderedHashmap *other, const void *key) {
530✔
233
        return _hashmap_move_one(HASHMAP_BASE(h), HASHMAP_BASE(other), key);
530✔
234
}
235

236
unsigned _hashmap_size(HashmapBase *h) _pure_;
237
static inline unsigned hashmap_size(Hashmap *h) {
1,378,720✔
238
        return _hashmap_size(HASHMAP_BASE(h));
1,083,111✔
239
}
240
static inline unsigned ordered_hashmap_size(OrderedHashmap *h) {
9,100,612✔
241
        return _hashmap_size(HASHMAP_BASE(h));
9,005,213✔
242
}
243

244
static inline bool hashmap_isempty(Hashmap *h) {
913,695✔
245
        return hashmap_size(h) == 0;
850,498✔
246
}
247
static inline bool ordered_hashmap_isempty(OrderedHashmap *h) {
1,285,800✔
248
        return ordered_hashmap_size(h) == 0;
1,285,748✔
249
}
250

251
unsigned _hashmap_buckets(HashmapBase *h) _pure_;
252
static inline unsigned hashmap_buckets(Hashmap *h) {
2,093✔
253
        return _hashmap_buckets(HASHMAP_BASE(h));
2,093✔
254
}
255
static inline unsigned ordered_hashmap_buckets(OrderedHashmap *h) {
8✔
256
        return _hashmap_buckets(HASHMAP_BASE(h));
8✔
257
}
258

259
bool _hashmap_iterate(HashmapBase *h, Iterator *i, void **value, const void **key);
260
static inline bool hashmap_iterate(Hashmap *h, Iterator *i, void **value, const void **key) {
22,904,300✔
261
        return _hashmap_iterate(HASHMAP_BASE(h), i, value, key);
22,904,300✔
262
}
263
static inline bool ordered_hashmap_iterate(OrderedHashmap *h, Iterator *i, void **value, const void **key) {
8,777,907✔
264
        return _hashmap_iterate(HASHMAP_BASE(h), i, value, key);
8,777,907✔
265
}
266

267
void _hashmap_clear(HashmapBase *h, free_func_t default_free_key, free_func_t default_free_value);
268
static inline void hashmap_clear(Hashmap *h) {
4,044✔
269
        _hashmap_clear(HASHMAP_BASE(h), NULL, NULL);
4,044✔
270
}
70✔
271
static inline void ordered_hashmap_clear(OrderedHashmap *h) {
17,264✔
272
        _hashmap_clear(HASHMAP_BASE(h), NULL, NULL);
17,264✔
273
}
24✔
274

275
/*
276
 * Note about all *_first*() functions
277
 *
278
 * For plain Hashmaps and Sets the order of entries is undefined.
279
 * The functions find whatever entry is first in the implementation
280
 * internal order.
281
 *
282
 * Only for OrderedHashmaps the order is well defined and finding
283
 * the first entry is O(1).
284
 */
285

286
void *_hashmap_first_key_and_value(HashmapBase *h, bool remove, void **ret_key);
287
static inline void *hashmap_steal_first_key_and_value(Hashmap *h, void **ret) {
43,495✔
288
        return _hashmap_first_key_and_value(HASHMAP_BASE(h), true, ret);
43,495✔
289
}
290
static inline void *ordered_hashmap_steal_first_key_and_value(OrderedHashmap *h, void **ret) {
×
291
        return _hashmap_first_key_and_value(HASHMAP_BASE(h), true, ret);
×
292
}
293
static inline void *hashmap_first_key_and_value(Hashmap *h, void **ret) {
294
        return _hashmap_first_key_and_value(HASHMAP_BASE(h), false, ret);
295
}
296
static inline void *ordered_hashmap_first_key_and_value(OrderedHashmap *h, void **ret) {
297
        return _hashmap_first_key_and_value(HASHMAP_BASE(h), false, ret);
298
}
299

300
static inline void *hashmap_steal_first(Hashmap *h) {
694,347✔
301
        return _hashmap_first_key_and_value(HASHMAP_BASE(h), true, NULL);
694,347✔
302
}
303
static inline void *ordered_hashmap_steal_first(OrderedHashmap *h) {
7,606,730✔
304
        return _hashmap_first_key_and_value(HASHMAP_BASE(h), true, NULL);
7,606,730✔
305
}
306
static inline void *hashmap_first(Hashmap *h) {
50,788✔
307
        return _hashmap_first_key_and_value(HASHMAP_BASE(h), false, NULL);
50,788✔
308
}
309
static inline void *ordered_hashmap_first(OrderedHashmap *h) {
246,931✔
310
        return _hashmap_first_key_and_value(HASHMAP_BASE(h), false, NULL);
246,931✔
311
}
312

313
static inline void *_hashmap_first_key(HashmapBase *h, bool remove) {
893,588✔
314
        void *key = NULL;
893,588✔
315

316
        (void) _hashmap_first_key_and_value(HASHMAP_BASE(h), remove, &key);
893,588✔
317
        return key;
893,588✔
318
}
319
static inline void *hashmap_steal_first_key(Hashmap *h) {
877,019✔
320
        return _hashmap_first_key(HASHMAP_BASE(h), true);
877,019✔
321
}
322
static inline void *ordered_hashmap_steal_first_key(OrderedHashmap *h) {
2✔
323
        return _hashmap_first_key(HASHMAP_BASE(h), true);
2✔
324
}
325
static inline void *hashmap_first_key(Hashmap *h) {
16,183✔
326
        return _hashmap_first_key(HASHMAP_BASE(h), false);
16,183✔
327
}
328
static inline void *ordered_hashmap_first_key(OrderedHashmap *h) {
384✔
329
        return _hashmap_first_key(HASHMAP_BASE(h), false);
384✔
330
}
331

332
#define hashmap_clear_with_destructor(h, f)                     \
333
        ({                                                      \
334
                Hashmap *_h = (h);                              \
335
                void *_item;                                    \
336
                while ((_item = hashmap_steal_first(_h)))       \
337
                        f(_item);                               \
338
                _h;                                             \
339
        })
340
#define hashmap_free_with_destructor(h, f)                      \
341
        hashmap_free(hashmap_clear_with_destructor(h, f))
342
#define ordered_hashmap_clear_with_destructor(h, f)                     \
343
        ({                                                              \
344
                OrderedHashmap *_h = (h);                               \
345
                void *_item;                                            \
346
                while ((_item = ordered_hashmap_steal_first(_h)))       \
347
                        f(_item);                                       \
348
                _h;                                                     \
349
        })
350
#define ordered_hashmap_free_with_destructor(h, f)                      \
351
        ordered_hashmap_free(ordered_hashmap_clear_with_destructor(h, f))
352

353
/* no hashmap_next */
354
void* ordered_hashmap_next(OrderedHashmap *h, const void *key);
355

356
char** _hashmap_get_strv(HashmapBase *h);
357
static inline char** hashmap_get_strv(Hashmap *h) {
104,269✔
358
        return _hashmap_get_strv(HASHMAP_BASE(h));
104,269✔
359
}
360
static inline char** ordered_hashmap_get_strv(OrderedHashmap *h) {
1✔
361
        return _hashmap_get_strv(HASHMAP_BASE(h));
1✔
362
}
363

364
int _hashmap_dump_sorted(HashmapBase *h, void ***ret, size_t *ret_n);
365
static inline int hashmap_dump_sorted(Hashmap *h, void ***ret, size_t *ret_n) {
154✔
366
        return _hashmap_dump_sorted(HASHMAP_BASE(h), ret, ret_n);
154✔
367
}
368
static inline int ordered_hashmap_dump_sorted(OrderedHashmap *h, void ***ret, size_t *ret_n) {
4✔
369
        return _hashmap_dump_sorted(HASHMAP_BASE(h), ret, ret_n);
4✔
370
}
371
static inline int set_dump_sorted(Set *h, void ***ret, size_t *ret_n) {
264✔
372
        return _hashmap_dump_sorted(HASHMAP_BASE(h), ret, ret_n);
264✔
373
}
374

375
int _hashmap_dump_keys_sorted(HashmapBase *h, void ***ret, size_t *ret_n);
376
static inline int hashmap_dump_keys_sorted(Hashmap *h, void ***ret, size_t *ret_n) {
85✔
377
        return _hashmap_dump_keys_sorted(HASHMAP_BASE(h), ret, ret_n);
85✔
378
}
379
static inline int ordered_hashmap_dump_keys_sorted(OrderedHashmap *h, void ***ret, size_t *ret_n) {
2✔
380
        return _hashmap_dump_keys_sorted(HASHMAP_BASE(h), ret, ret_n);
2✔
381
}
382

383
/*
384
 * Hashmaps are iterated in unpredictable order.
385
 * OrderedHashmaps are an exception to this. They are iterated in the order
386
 * the entries were inserted.
387
 * It is safe to remove the current entry.
388
 */
389
#define _HASHMAP_BASE_FOREACH(e, h, i) \
390
        for (Iterator i = ITERATOR_FIRST; _hashmap_iterate((h), &i, (void**)&(e), NULL); )
391
#define HASHMAP_BASE_FOREACH(e, h) \
392
        _HASHMAP_BASE_FOREACH(e, h, UNIQ_T(i, UNIQ))
393

394
#define _HASHMAP_FOREACH(e, h, i) \
395
        for (Iterator i = ITERATOR_FIRST; hashmap_iterate((h), &i, (void**)&(e), NULL); )
396
#define HASHMAP_FOREACH(e, h) \
397
        _HASHMAP_FOREACH(e, h, UNIQ_T(i, UNIQ))
398

399
#define _ORDERED_HASHMAP_FOREACH(e, h, i) \
400
        for (Iterator i = ITERATOR_FIRST; ordered_hashmap_iterate((h), &i, (void**)&(e), NULL); )
401
#define ORDERED_HASHMAP_FOREACH(e, h) \
402
        _ORDERED_HASHMAP_FOREACH(e, h, UNIQ_T(i, UNIQ))
403

404
#define _HASHMAP_BASE_FOREACH_KEY(e, k, h, i) \
405
        for (Iterator i = ITERATOR_FIRST; _hashmap_iterate((h), &i, (void**)&(e), (const void**) &(k)); )
406
#define HASHMAP_BASE_FOREACH_KEY(e, k, h) \
407
        _HASHMAP_BASE_FOREACH_KEY(e, k, h, UNIQ_T(i, UNIQ))
408

409
#define _HASHMAP_FOREACH_KEY(e, k, h, i) \
410
        for (Iterator i = ITERATOR_FIRST; hashmap_iterate((h), &i, (void**)&(e), (const void**) &(k)); )
411
#define HASHMAP_FOREACH_KEY(e, k, h) \
412
        _HASHMAP_FOREACH_KEY(e, k, h, UNIQ_T(i, UNIQ))
413

414
#define _ORDERED_HASHMAP_FOREACH_KEY(e, k, h, i) \
415
        for (Iterator i = ITERATOR_FIRST; ordered_hashmap_iterate((h), &i, (void**)&(e), (const void**) &(k)); )
416
#define ORDERED_HASHMAP_FOREACH_KEY(e, k, h) \
417
        _ORDERED_HASHMAP_FOREACH_KEY(e, k, h, UNIQ_T(i, UNIQ))
418

419
DEFINE_TRIVIAL_CLEANUP_FUNC(Hashmap*, hashmap_free);
731,946✔
420
DEFINE_TRIVIAL_CLEANUP_FUNC(OrderedHashmap*, ordered_hashmap_free);
56,912✔
421

422
#define _cleanup_hashmap_free_ _cleanup_(hashmap_freep)
423
#define _cleanup_ordered_hashmap_free_ _cleanup_(ordered_hashmap_freep)
424

425
DEFINE_TRIVIAL_CLEANUP_FUNC(IteratedCache*, iterated_cache_free);
426

427
#define _cleanup_iterated_cache_free_ _cleanup_(iterated_cache_freep)
428

429
void hashmap_trim_pools(void);
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc