bitmap.h 1.9 KB

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