]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/shared/bitmap.h
license: LGPL-2.1+ -> LGPL-2.1-or-later
[thirdparty/systemd.git] / src / shared / bitmap.h
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3
4 #include <stdbool.h>
5
6 #include "hashmap.h"
7 #include "macro.h"
8
9 typedef struct Bitmap {
10 uint64_t *bitmaps;
11 size_t n_bitmaps;
12 size_t bitmaps_allocated;
13 } Bitmap;
14
15 Bitmap *bitmap_new(void);
16 Bitmap *bitmap_copy(Bitmap *b);
17 int bitmap_ensure_allocated(Bitmap **b);
18 void bitmap_free(Bitmap *b);
19
20 int bitmap_set(Bitmap *b, unsigned n);
21 void bitmap_unset(Bitmap *b, unsigned n);
22 bool bitmap_isset(const Bitmap *b, unsigned n);
23 bool bitmap_isclear(const Bitmap *b);
24 void bitmap_clear(Bitmap *b);
25
26 bool bitmap_iterate(const Bitmap *b, Iterator *i, unsigned *n);
27
28 bool bitmap_equal(const Bitmap *a, const Bitmap *b);
29
30 #define _BITMAP_FOREACH(n, b, i) \
31 for (Iterator i = {}; bitmap_iterate((b), &i, (unsigned*)&(n)); )
32 #define BITMAP_FOREACH(n, b) \
33 _BITMAP_FOREACH(n, b, UNIQ_T(i, UNIQ))
34
35 DEFINE_TRIVIAL_CLEANUP_FUNC(Bitmap*, bitmap_free);
36
37 #define _cleanup_bitmap_free_ _cleanup_(bitmap_freep)