xref: /openbsd-src/usr.bin/ssh/bitmap.h (revision 309059cfdd981b85d5916e0ae910631503a6f54f)
1*309059cfSdjm /* $OpenBSD: bitmap.h,v 1.2 2017/10/20 01:56:39 djm Exp $ */
278e9a853Sdjm /*
378e9a853Sdjm  * Copyright (c) 2015 Damien Miller <djm@mindrot.org>
478e9a853Sdjm  *
578e9a853Sdjm  * Permission to use, copy, modify, and distribute this software for any
678e9a853Sdjm  * purpose with or without fee is hereby granted, provided that the above
778e9a853Sdjm  * copyright notice and this permission notice appear in all copies.
878e9a853Sdjm  *
978e9a853Sdjm  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
1078e9a853Sdjm  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1178e9a853Sdjm  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
1278e9a853Sdjm  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1378e9a853Sdjm  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
1478e9a853Sdjm  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
1578e9a853Sdjm  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1678e9a853Sdjm  */
1778e9a853Sdjm 
1878e9a853Sdjm #ifndef _BITMAP_H
1978e9a853Sdjm #define _BITMAP_H
2078e9a853Sdjm 
2178e9a853Sdjm #include <sys/types.h>
2278e9a853Sdjm 
2378e9a853Sdjm /* Simple bit vector routines */
2478e9a853Sdjm 
2578e9a853Sdjm struct bitmap;
2678e9a853Sdjm 
2778e9a853Sdjm /* Allocate a new bitmap. Returns NULL on allocation failure. */
2878e9a853Sdjm struct bitmap *bitmap_new(void);
2978e9a853Sdjm 
3078e9a853Sdjm /* Free a bitmap */
3178e9a853Sdjm void bitmap_free(struct bitmap *b);
3278e9a853Sdjm 
3378e9a853Sdjm /* Zero an existing bitmap */
3478e9a853Sdjm void bitmap_zero(struct bitmap *b);
3578e9a853Sdjm 
3678e9a853Sdjm /* Test whether a bit is set in a bitmap. */
3778e9a853Sdjm int bitmap_test_bit(struct bitmap *b, u_int n);
3878e9a853Sdjm 
3978e9a853Sdjm /* Set a bit in a bitmap. Returns 0 on success or -1 on error */
4078e9a853Sdjm int bitmap_set_bit(struct bitmap *b, u_int n);
4178e9a853Sdjm 
4278e9a853Sdjm /* Clear a bit in a bitmap */
4378e9a853Sdjm void bitmap_clear_bit(struct bitmap *b, u_int n);
4478e9a853Sdjm 
4578e9a853Sdjm /* Return the number of bits in a bitmap (i.e. the position of the MSB) */
4678e9a853Sdjm size_t bitmap_nbits(struct bitmap *b);
4778e9a853Sdjm 
4878e9a853Sdjm /* Return the number of bytes needed to represent a bitmap */
4978e9a853Sdjm size_t bitmap_nbytes(struct bitmap *b);
5078e9a853Sdjm 
5178e9a853Sdjm /* Convert a bitmap to a big endian byte string */
5278e9a853Sdjm int bitmap_to_string(struct bitmap *b, void *p, size_t l);
5378e9a853Sdjm 
5478e9a853Sdjm /* Convert a big endian byte string to a bitmap */
5578e9a853Sdjm int bitmap_from_string(struct bitmap *b, const void *p, size_t l);
5678e9a853Sdjm 
5778e9a853Sdjm #endif /* _BITMAP_H */
58