d5fa18e4062bc95b976dde5057b650dbb53c230e
[platform/upstream/libsolv.git] / src / bitmap.h
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 SATSOLVER_BITMAP_H
14 #define SATSOLVER_BITMAP_H
15
16 typedef struct _Map {
17   unsigned char *map;
18   int size;
19 } Map;
20
21 #define MAPZERO(m) (memset((m)->map, 0, (m)->size))
22 /* set bit */
23 #define MAPSET(m, n) ((m)->map[(n) >> 3] |= 1 << ((n) & 7))
24 /* clear bit */
25 #define MAPCLR(m, n) ((m)->map[(n) >> 3] &= ~(1 << ((n) & 7)))
26 /* test bit */
27 #define MAPTST(m, n) ((m)->map[(n) >> 3] & (1 << ((n) & 7)))
28
29 extern void map_init(Map *m, int n);
30 extern void map_init_clone(Map *t, Map *s);
31 extern void map_grow(Map *m, int n);
32 extern void map_free(Map *m);
33
34 static inline void map_empty(Map *m)
35 {
36   MAPZERO(m);
37 }
38 static inline void map_set(Map *m, int n)
39 {
40   MAPSET(m, n);
41 }
42 static inline void map_clr(Map *m, int n)
43 {
44   MAPCLR(m, n);
45 }
46 static inline int map_tst(Map *m, int n)
47 {
48   return MAPTST(m, n);
49 }
50
51 #endif /* SATSOLVER_BITMAP_H */