]>
Commit | Line | Data |
---|---|---|
a032b68d | 1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ |
7035cd9e MP |
2 | #pragma once |
3 | ||
4c89c718 MP |
4 | #include <stdbool.h> |
5 | ||
7035cd9e | 6 | #include "hashmap.h" |
4c89c718 | 7 | #include "macro.h" |
7035cd9e | 8 | |
f2dec872 BR |
9 | typedef struct Bitmap { |
10 | uint64_t *bitmaps; | |
11 | size_t n_bitmaps; | |
f2dec872 | 12 | } Bitmap; |
7035cd9e | 13 | |
3a6ce677 BR |
14 | Bitmap* bitmap_new(void); |
15 | Bitmap* bitmap_copy(Bitmap *b); | |
7035cd9e | 16 | int bitmap_ensure_allocated(Bitmap **b); |
3a6ce677 | 17 | Bitmap* bitmap_free(Bitmap *b); |
7035cd9e MP |
18 | |
19 | int bitmap_set(Bitmap *b, unsigned n); | |
20 | void bitmap_unset(Bitmap *b, unsigned n); | |
f2dec872 BR |
21 | bool bitmap_isset(const Bitmap *b, unsigned n); |
22 | bool bitmap_isclear(const Bitmap *b); | |
7035cd9e MP |
23 | void bitmap_clear(Bitmap *b); |
24 | ||
f2dec872 | 25 | bool bitmap_iterate(const Bitmap *b, Iterator *i, unsigned *n); |
7035cd9e | 26 | |
f2dec872 | 27 | bool bitmap_equal(const Bitmap *a, const Bitmap *b); |
7035cd9e | 28 | |
a032b68d MB |
29 | #define _BITMAP_FOREACH(n, b, i) \ |
30 | for (Iterator i = {}; bitmap_iterate((b), &i, (unsigned*)&(n)); ) | |
31 | #define BITMAP_FOREACH(n, b) \ | |
32 | _BITMAP_FOREACH(n, b, UNIQ_T(i, UNIQ)) | |
7035cd9e MP |
33 | |
34 | DEFINE_TRIVIAL_CLEANUP_FUNC(Bitmap*, bitmap_free); | |
35 | ||
36 | #define _cleanup_bitmap_free_ _cleanup_(bitmap_freep) |