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 /*
9  * bitmap.h
10  *
11  */
12 
13 #ifndef LIBSOLV_BITMAP_H
14 #define LIBSOLV_BITMAP_H
15 
16 #include <string.h>
17 
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21 
22 typedef struct s_Map {
23   unsigned char *map;
24   int size;
25 } Map;
26 
27 #define MAPZERO(m) (memset((m)->map, 0, (m)->size))
28 /* set all bits */
29 #define MAPSETALL(m) (memset((m)->map, 0xff, (m)->size))
30 /* set bit */
31 #define MAPSET(m, n) ((m)->map[(n) >> 3] |= 1 << ((n) & 7))
32 /* clear bit */
33 #define MAPCLR(m, n) ((m)->map[(n) >> 3] &= ~(1 << ((n) & 7)))
34 /* test bit */
35 #define MAPTST(m, n) ((m)->map[(n) >> 3] & (1 << ((n) & 7)))
36 /* clear some bits at a position */
37 #define MAPCLR_AT(m, n) ((m)->map[(n) >> 3] = 0)
38 
39 extern void map_init(Map *m, int n);
40 extern void map_init_clone(Map *target, const Map *source);
41 extern void map_grow(Map *m, int n);
42 extern void map_free(Map *m);
43 extern void map_and(Map *t, const Map *s);
44 extern void map_or(Map *t, const Map *s);
45 extern void map_subtract(Map *t, const Map *s);
46 extern void map_invertall(Map *m);
47 
map_empty(Map * m)48 static inline void map_empty(Map *m)
49 {
50   MAPZERO(m);
51 }
map_set(Map * m,int n)52 static inline void map_set(Map *m, int n)
53 {
54   MAPSET(m, n);
55 }
map_setall(Map * m)56 static inline void map_setall(Map *m)
57 {
58   MAPSETALL(m);
59 }
map_clr(Map * m,int n)60 static inline void map_clr(Map *m, int n)
61 {
62   MAPCLR(m, n);
63 }
map_tst(Map * m,int n)64 static inline int map_tst(Map *m, int n)
65 {
66   return MAPTST(m, n);
67 }
map_clr_at(Map * m,int n)68 static inline void map_clr_at(Map *m, int n)
69 {
70   MAPCLR_AT(m, n);
71 }
72 
73 #ifdef __cplusplus
74 }
75 #endif
76 
77 #endif /* LIBSOLV_BITMAP_H */
78