1 | /* $NetBSD: bitmap.h,v 1.5 2018/04/06 18:58:59 christos Exp $ */ |
2 | /* $OpenBSD: bitmap.h,v 1.2 2017/10/20 01:56:39 djm Exp $ */ |
3 | /* |
4 | * Copyright (c) 2015 Damien Miller <djm@mindrot.org> |
5 | * |
6 | * Permission to use, copy, modify, and distribute this software for any |
7 | * purpose with or without fee is hereby granted, provided that the above |
8 | * copyright notice and this permission notice appear in all copies. |
9 | * |
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
17 | */ |
18 | |
19 | #ifndef _BITMAP_H |
20 | #define _BITMAP_H |
21 | |
22 | #include <sys/types.h> |
23 | |
24 | /* Simple bit vector routines */ |
25 | |
26 | struct bitmap; |
27 | |
28 | /* Allocate a new bitmap. Returns NULL on allocation failure. */ |
29 | struct bitmap *bitmap_new(void); |
30 | |
31 | /* Free a bitmap */ |
32 | void bitmap_free(struct bitmap *b); |
33 | |
34 | /* Zero an existing bitmap */ |
35 | void bitmap_zero(struct bitmap *b); |
36 | |
37 | /* Test whether a bit is set in a bitmap. */ |
38 | int bitmap_test_bit(struct bitmap *b, u_int n); |
39 | |
40 | /* Set a bit in a bitmap. Returns 0 on success or -1 on error */ |
41 | int bitmap_set_bit(struct bitmap *b, u_int n); |
42 | |
43 | /* Clear a bit in a bitmap */ |
44 | void bitmap_clear_bit(struct bitmap *b, u_int n); |
45 | |
46 | /* Return the number of bits in a bitmap (i.e. the position of the MSB) */ |
47 | size_t bitmap_nbits(struct bitmap *b); |
48 | |
49 | /* Return the number of bytes needed to represent a bitmap */ |
50 | size_t bitmap_nbytes(struct bitmap *b); |
51 | |
52 | /* Convert a bitmap to a big endian byte string */ |
53 | int bitmap_to_string(struct bitmap *b, void *p, size_t l); |
54 | |
55 | /* Convert a big endian byte string to a bitmap */ |
56 | int bitmap_from_string(struct bitmap *b, const void *p, size_t l); |
57 | |
58 | #endif /* _BITMAP_H */ |
59 | |