bitmap.h revision 285031
1285031Sdes/* 2285031Sdes * Copyright (c) 2015 Damien Miller <djm@mindrot.org> 3285031Sdes * 4285031Sdes * Permission to use, copy, modify, and distribute this software for any 5285031Sdes * purpose with or without fee is hereby granted, provided that the above 6285031Sdes * copyright notice and this permission notice appear in all copies. 7285031Sdes * 8285031Sdes * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9285031Sdes * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10285031Sdes * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11285031Sdes * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12285031Sdes * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13285031Sdes * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14285031Sdes * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15285031Sdes */ 16285031Sdes 17285031Sdes#ifndef _BITMAP_H 18285031Sdes#define _BITMAP_H 19285031Sdes 20285031Sdes#include <sys/types.h> 21285031Sdes 22285031Sdes/* Simple bit vector routines */ 23285031Sdes 24285031Sdesstruct bitmap; 25285031Sdes 26285031Sdes/* Allocate a new bitmap. Returns NULL on allocation failure. */ 27285031Sdesstruct bitmap *bitmap_new(void); 28285031Sdes 29285031Sdes/* Free a bitmap */ 30285031Sdesvoid bitmap_free(struct bitmap *b); 31285031Sdes 32285031Sdes/* Zero an existing bitmap */ 33285031Sdesvoid bitmap_zero(struct bitmap *b); 34285031Sdes 35285031Sdes/* Test whether a bit is set in a bitmap. */ 36285031Sdesint bitmap_test_bit(struct bitmap *b, u_int n); 37285031Sdes 38285031Sdes/* Set a bit in a bitmap. Returns 0 on success or -1 on error */ 39285031Sdesint bitmap_set_bit(struct bitmap *b, u_int n); 40285031Sdes 41285031Sdes/* Clear a bit in a bitmap */ 42285031Sdesvoid bitmap_clear_bit(struct bitmap *b, u_int n); 43285031Sdes 44285031Sdes/* Return the number of bits in a bitmap (i.e. the position of the MSB) */ 45285031Sdessize_t bitmap_nbits(struct bitmap *b); 46285031Sdes 47285031Sdes/* Return the number of bytes needed to represent a bitmap */ 48285031Sdessize_t bitmap_nbytes(struct bitmap *b); 49285031Sdes 50285031Sdes/* Convert a bitmap to a big endian byte string */ 51285031Sdesint bitmap_to_string(struct bitmap *b, void *p, size_t l); 52285031Sdes 53285031Sdes/* Convert a big endian byte string to a bitmap */ 54285031Sdesint bitmap_from_string(struct bitmap *b, const void *p, size_t l); 55285031Sdes 56285031Sdes#endif /* _BITMAP_H */ 57