Line data Source code
1 : /* SPDX-License-Identifier: LGPL-2.1+ */ 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 ((i).idx = 0; bitmap_iterate((b), &(i), (unsigned*)&(n)); ) 32 : 33 2 : DEFINE_TRIVIAL_CLEANUP_FUNC(Bitmap*, bitmap_free); 34 : 35 : #define _cleanup_bitmap_free_ _cleanup_(bitmap_freep)