1 /* ELLE - Copyright 1985, 1987 by Ken Harrenstien, SRI International
2 * This software is quasi-public; it may be used freely with
3 * like software, but may NOT be sold or made part of licensed
4 * products without permission of the author.
7 * EEBIT Bit Array functions
11 /* Char-bit array functions. All assume that there are at least 8 bits
12 * in a byte, and that the number of bytes per word is a power of 2.
14 /* CHBBITS represents log 2 of the # of bits stored per chbit-array word.
15 * WDBITS already has log2 of the # of bytes per word, and we are
16 * assuming each byte has at least 8 bits, so log2(8) = 3.
18 #define CHBSIZE (WDSIZE*8) /* # bits per word */
19 #define CHBBITS (WDBITS+3) /* log2(CHBSIZE) */
20 #define CHBMASK (CHBSIZE-1)
21 #define CHBARYSIZ (128/CHBSIZE) /* # words per ASCII array */
23 /* CHBALLOC(size) - Allocates a char-bit array */
27 { return((int *)calloc((size
+ CHBSIZE
-1)/CHBSIZE
, (sizeof(int))));
30 /* CHBIT(array, char) - Tests bit in char-bit array
33 register int *array
, c
;
34 { return(array
[c
>> CHBBITS
] & (1 << (c
& CHBMASK
)));
36 /* CHBIS (array, char) - Sets bit in char-bit array
39 register int *array
, c
;
40 { array
[c
>> CHBBITS
] |= (1 << (c
& CHBMASK
));
42 /* CHBIC (array, char) - Clears bit in char-bit array
45 register int *array
, c
;
46 { array
[c
>> CHBBITS
] &= ~(1 << (c
& CHBMASK
));