]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/shared/bitmap.h
license: LGPL-2.1+ -> LGPL-2.1-or-later
[thirdparty/systemd.git] / src / shared / bitmap.h
CommitLineData
db9ecf05 1/* SPDX-License-Identifier: LGPL-2.1-or-later */
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
9typedef struct Bitmap {
10 uint64_t *bitmaps;
11 size_t n_bitmaps;
12 size_t bitmaps_allocated;
13} Bitmap;
5ffa42cb
TG
14
15Bitmap *bitmap_new(void);
17c8de63 16Bitmap *bitmap_copy(Bitmap *b);
5ffa42cb 17int bitmap_ensure_allocated(Bitmap **b);
17c8de63 18void bitmap_free(Bitmap *b);
5ffa42cb
TG
19
20int bitmap_set(Bitmap *b, unsigned n);
21void bitmap_unset(Bitmap *b, unsigned n);
8594c8a5
ZJS
22bool bitmap_isset(const Bitmap *b, unsigned n);
23bool bitmap_isclear(const Bitmap *b);
5ffa42cb
TG
24void bitmap_clear(Bitmap *b);
25
8594c8a5 26bool bitmap_iterate(const Bitmap *b, Iterator *i, unsigned *n);
5ffa42cb 27
8594c8a5 28bool 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
35DEFINE_TRIVIAL_CLEANUP_FUNC(Bitmap*, bitmap_free);
36
37#define _cleanup_bitmap_free_ _cleanup_(bitmap_freep)