bitmap.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * Copyright (c) 2007-2011, Novell Inc.
  3. *
  4. * This program is licensed under the BSD license, read LICENSE.BSD
  5. * for further information
  6. */
  7. /*
  8. * bitmap.h
  9. *
  10. */
  11. #ifndef LIBSOLV_BITMAP_H
  12. #define LIBSOLV_BITMAP_H
  13. #include <string.h>
  14. #ifdef __cplusplus
  15. extern "C" {
  16. #endif
  17. typedef struct s_Map {
  18. unsigned char *map;
  19. int size;
  20. } Map;
  21. #define MAPZERO(m) (memset((m)->map, 0, (m)->size))
  22. /* set all bits */
  23. #define MAPSETALL(m) (memset((m)->map, 0xff, (m)->size))
  24. /* set bit */
  25. #define MAPSET(m, n) ((m)->map[(n) >> 3] |= 1 << ((n) & 7))
  26. /* clear bit */
  27. #define MAPCLR(m, n) ((m)->map[(n) >> 3] &= ~(1 << ((n) & 7)))
  28. /* test bit */
  29. #define MAPTST(m, n) ((m)->map[(n) >> 3] & (1 << ((n) & 7)))
  30. /* clear some bits at a position */
  31. #define MAPCLR_AT(m, n) ((m)->map[(n) >> 3] = 0)
  32. extern void map_init(Map *m, int n);
  33. extern void map_init_clone(Map *target, const Map *source);
  34. extern void map_grow(Map *m, int n);
  35. extern void map_free(Map *m);
  36. extern void map_and(Map *t, const Map *s);
  37. extern void map_or(Map *t, const Map *s);
  38. extern void map_subtract(Map *t, const Map *s);
  39. extern void map_invertall(Map *m);
  40. static inline void map_empty(Map *m)
  41. {
  42. MAPZERO(m);
  43. }
  44. static inline void map_set(Map *m, int n)
  45. {
  46. MAPSET(m, n);
  47. }
  48. static inline void map_setall(Map *m)
  49. {
  50. MAPSETALL(m);
  51. }
  52. static inline void map_clr(Map *m, int n)
  53. {
  54. MAPCLR(m, n);
  55. }
  56. static inline int map_tst(Map *m, int n)
  57. {
  58. return MAPTST(m, n);
  59. }
  60. static inline void map_clr_at(Map *m, int n)
  61. {
  62. MAPCLR_AT(m, n);
  63. }
  64. #ifdef __cplusplus
  65. }
  66. #endif
  67. #endif /* LIBSOLV_BITMAP_H */