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