]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/basic/bitmap.h
63fdbe8beaa5fce839705e2564a21d1914bbc9bd
[thirdparty/systemd.git] / src / basic / bitmap.h
1 #pragma once
2
3 /***
4 This file is part of systemd.
5
6 Copyright 2015 Tom Gundersen
7
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
12
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20 ***/
21
22 #include <stdbool.h>
23
24 #include "hashmap.h"
25 #include "macro.h"
26
27 typedef struct Bitmap Bitmap;
28
29 Bitmap *bitmap_new(void);
30 Bitmap *bitmap_copy(Bitmap *b);
31 int bitmap_ensure_allocated(Bitmap **b);
32 void bitmap_free(Bitmap *b);
33
34 int bitmap_set(Bitmap *b, unsigned n);
35 void bitmap_unset(Bitmap *b, unsigned n);
36 bool bitmap_isset(Bitmap *b, unsigned n);
37 bool bitmap_isclear(Bitmap *b);
38 void bitmap_clear(Bitmap *b);
39
40 bool bitmap_iterate(Bitmap *b, Iterator *i, unsigned *n);
41
42 bool bitmap_equal(Bitmap *a, Bitmap *b);
43
44 #define BITMAP_FOREACH(n, b, i) \
45 for ((i).idx = 0; bitmap_iterate((b), &(i), (unsigned*)&(n)); )
46
47 DEFINE_TRIVIAL_CLEANUP_FUNC(Bitmap*, bitmap_free);
48
49 #define _cleanup_bitmap_free_ _cleanup_(bitmap_freep)