]> git.proxmox.com Git - systemd.git/blame - src/shared/bitmap.h
New upstream version 249~rc1
[systemd.git] / src / shared / bitmap.h
CommitLineData
a032b68d 1/* SPDX-License-Identifier: LGPL-2.1-or-later */
7035cd9e
MP
2#pragma once
3
4c89c718
MP
4#include <stdbool.h>
5
7035cd9e 6#include "hashmap.h"
4c89c718 7#include "macro.h"
7035cd9e 8
f2dec872
BR
9typedef struct Bitmap {
10 uint64_t *bitmaps;
11 size_t n_bitmaps;
f2dec872 12} Bitmap;
7035cd9e 13
3a6ce677
BR
14Bitmap* bitmap_new(void);
15Bitmap* bitmap_copy(Bitmap *b);
7035cd9e 16int bitmap_ensure_allocated(Bitmap **b);
3a6ce677 17Bitmap* bitmap_free(Bitmap *b);
7035cd9e
MP
18
19int bitmap_set(Bitmap *b, unsigned n);
20void bitmap_unset(Bitmap *b, unsigned n);
f2dec872
BR
21bool bitmap_isset(const Bitmap *b, unsigned n);
22bool bitmap_isclear(const Bitmap *b);
7035cd9e
MP
23void bitmap_clear(Bitmap *b);
24
f2dec872 25bool bitmap_iterate(const Bitmap *b, Iterator *i, unsigned *n);
7035cd9e 26
f2dec872 27bool bitmap_equal(const Bitmap *a, const Bitmap *b);
7035cd9e 28
a032b68d
MB
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))
7035cd9e
MP
33
34DEFINE_TRIVIAL_CLEANUP_FUNC(Bitmap*, bitmap_free);
35
36#define _cleanup_bitmap_free_ _cleanup_(bitmap_freep)