]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
5ffa42cb TG |
2 | #pragma once |
3 | ||
11c3a366 TA |
4 | #include <stdbool.h> |
5 | ||
cb57dd41 | 6 | #include "hashmap.h" |
71d35b6b | 7 | #include "macro.h" |
5ffa42cb | 8 | |
23d5dd16 ZJS |
9 | typedef struct Bitmap { |
10 | uint64_t *bitmaps; | |
11 | size_t n_bitmaps; | |
12 | size_t bitmaps_allocated; | |
13 | } Bitmap; | |
5ffa42cb TG |
14 | |
15 | Bitmap *bitmap_new(void); | |
17c8de63 | 16 | Bitmap *bitmap_copy(Bitmap *b); |
5ffa42cb | 17 | int bitmap_ensure_allocated(Bitmap **b); |
17c8de63 | 18 | void bitmap_free(Bitmap *b); |
5ffa42cb TG |
19 | |
20 | int bitmap_set(Bitmap *b, unsigned n); | |
21 | void bitmap_unset(Bitmap *b, unsigned n); | |
8594c8a5 ZJS |
22 | bool bitmap_isset(const Bitmap *b, unsigned n); |
23 | bool bitmap_isclear(const Bitmap *b); | |
5ffa42cb TG |
24 | void bitmap_clear(Bitmap *b); |
25 | ||
8594c8a5 | 26 | bool bitmap_iterate(const Bitmap *b, Iterator *i, unsigned *n); |
5ffa42cb | 27 | |
8594c8a5 | 28 | bool bitmap_equal(const Bitmap *a, const Bitmap *b); |
5ffa42cb | 29 | |
90e74a66 ZJS |
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)) | |
5ffa42cb TG |
34 | |
35 | DEFINE_TRIVIAL_CLEANUP_FUNC(Bitmap*, bitmap_free); | |
36 | ||
37 | #define _cleanup_bitmap_free_ _cleanup_(bitmap_freep) |