summaryrefslogtreecommitdiff
path: root/src/bitmap.h
blob: 6609678f7a3d6575c0364c2b9af70f9283de1b4d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
 * Copyright (c) 2007-2011, Novell Inc.
 *
 * This program is licensed under the BSD license, read LICENSE.BSD
 * for further information
 */

/*
 * bitmap.h
 *
 */

#ifndef LIBSOLV_BITMAP_H
#define LIBSOLV_BITMAP_H

#include <string.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef struct s_Map {
  unsigned char *map;
  int size;
} Map;

#define MAPZERO(m) (memset((m)->map, 0, (m)->size))
/* set all bits */
#define MAPSETALL(m) (memset((m)->map, 0xff, (m)->size))
/* set bit */
#define MAPSET(m, n) ((m)->map[(n) >> 3] |= 1 << ((n) & 7))
/* clear bit */
#define MAPCLR(m, n) ((m)->map[(n) >> 3] &= ~(1 << ((n) & 7)))
/* test bit */
#define MAPTST(m, n) ((m)->map[(n) >> 3] & (1 << ((n) & 7)))
/* clear some bits at a position */
#define MAPCLR_AT(m, n) ((m)->map[(n) >> 3] = 0)

extern void map_init(Map *m, int n);
extern void map_init_clone(Map *target, const Map *source);
extern void map_grow(Map *m, int n);
extern void map_free(Map *m);
extern void map_and(Map *t, const Map *s);
extern void map_or(Map *t, const Map *s);
extern void map_subtract(Map *t, const Map *s);
extern void map_invertall(Map *m);

static inline void map_empty(Map *m)
{
  MAPZERO(m);
}
static inline void map_set(Map *m, int n)
{
  MAPSET(m, n);
}
static inline void map_setall(Map *m)
{
  MAPSETALL(m);
}
static inline void map_clr(Map *m, int n)
{
  MAPCLR(m, n);
}
static inline int map_tst(Map *m, int n)
{
  return MAPTST(m, n);
}
static inline void map_clr_at(Map *m, int n)
{
  MAPCLR_AT(m, n);
}

#ifdef __cplusplus
}
#endif

#endif /* LIBSOLV_BITMAP_H */