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 } Bitmap;
13 
14 Bitmap* bitmap_new(void);
15 Bitmap* bitmap_copy(Bitmap *b);
16 int bitmap_ensure_allocated(Bitmap **b);
17 Bitmap* bitmap_free(Bitmap *b);
18 
19 int bitmap_set(Bitmap *b, unsigned n);
20 void bitmap_unset(Bitmap *b, unsigned n);
21 bool bitmap_isset(const Bitmap *b, unsigned n);
22 bool bitmap_isclear(const Bitmap *b);
23 void bitmap_clear(Bitmap *b);
24 
25 bool bitmap_iterate(const Bitmap *b, Iterator *i, unsigned *n);
26 
27 bool bitmap_equal(const Bitmap *a, const Bitmap *b);
28 
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))
33 
34 DEFINE_TRIVIAL_CLEANUP_FUNC(Bitmap*, bitmap_free);
35 
36 #define _cleanup_bitmap_free_ _cleanup_(bitmap_freep)
37