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