Lines Matching defs:bmp

26 	struct bitmask *bmp;
28 bmp = malloc(sizeof(*bmp));
29 if (!bmp)
31 bmp->size = n;
32 bmp->maskp = calloc(longsperbits(n), sizeof(unsigned long));
33 if (!bmp->maskp) {
34 free(bmp);
37 return bmp;
41 void bitmask_free(struct bitmask *bmp)
43 if (!bmp)
45 free(bmp->maskp);
46 bmp->maskp = (unsigned long *)0xdeadcdef; /* double free tripwire */
47 free(bmp);
52 * routines that actually understand the layout of bmp->maskp[].
61 /* Return the value (0 or 1) of bit n in bitmask bmp */
62 static unsigned int _getbit(const struct bitmask *bmp, unsigned int n)
64 if (n < bmp->size)
65 return (bmp->maskp[n/bitsperlong] >> (n % bitsperlong)) & 1;
70 /* Set bit n in bitmask bmp to value v (0 or 1) */
71 static void _setbit(struct bitmask *bmp, unsigned int n, unsigned int v)
73 if (n < bmp->size) {
75 bmp->maskp[n/bitsperlong] |= 1UL << (n % bitsperlong);
77 bmp->maskp[n/bitsperlong] &=
115 struct bitmask *bitmask_setbit(struct bitmask *bmp, unsigned int i)
117 _setbit(bmp, i, 1);
118 return bmp;
121 /* Set all bits in bitmask: bmp = ~0 */
122 struct bitmask *bitmask_setall(struct bitmask *bmp)
125 for (i = 0; i < bmp->size; i++)
126 _setbit(bmp, i, 1);
127 return bmp;
130 /* Clear all bits in bitmask: bmp = 0 */
131 struct bitmask *bitmask_clearall(struct bitmask *bmp)
134 for (i = 0; i < bmp->size; i++)
135 _setbit(bmp, i, 0);
136 return bmp;
140 int bitmask_isallclear(const struct bitmask *bmp)
143 for (i = 0; i < bmp->size; i++)
144 if (_getbit(bmp, i))
150 int bitmask_isbitset(const struct bitmask *bmp, unsigned int i)
152 return _getbit(bmp, i);
156 unsigned int bitmask_first(const struct bitmask *bmp)
158 return bitmask_next(bmp, 0);
162 unsigned int bitmask_last(const struct bitmask *bmp)
165 unsigned int m = bmp->size;
166 for (i = 0; i < bmp->size; i++)
167 if (_getbit(bmp, i))
173 unsigned int bitmask_next(const struct bitmask *bmp, unsigned int i)
176 for (n = i; n < bmp->size; n++)
177 if (_getbit(bmp, n))
192 int bitmask_parselist(const char *buf, struct bitmask *bmp)
196 bitmask_clearall(bmp);
227 if (b >= bmp->size)
230 _setbit(bmp, a, 1);
236 bitmask_clearall(bmp);
262 * Write decimal list representation of bmp to buf.
275 int bitmask_displaylist(char *buf, int buflen, const struct bitmask *bmp)
283 rbot = cur = bitmask_first(bmp);
284 while (cur < bmp->size) {
286 cur = bitmask_next(bmp, cur+1);
287 if (cur >= bmp->size || cur > rtop + 1) {