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.
|
---|
5 | */
|
---|
6 | /*
|
---|
7 | * EEBIT Bit Array functions
|
---|
8 | */
|
---|
9 | #include "sb.h"
|
---|
10 |
|
---|
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.
|
---|
13 | */
|
---|
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.
|
---|
17 | */
|
---|
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 */
|
---|
22 |
|
---|
23 | /* CHBALLOC(size) - Allocates a char-bit array */
|
---|
24 | int *
|
---|
25 | chballoc(size)
|
---|
26 | int size;
|
---|
27 | { return((int *)calloc((size + CHBSIZE-1)/CHBSIZE, (sizeof(int))));
|
---|
28 | }
|
---|
29 |
|
---|
30 | /* CHBIT(array, char) - Tests bit in char-bit array
|
---|
31 | */
|
---|
32 | chbit(array,c)
|
---|
33 | register int *array, c;
|
---|
34 | { return(array[c >> CHBBITS] & (1 << (c & CHBMASK)));
|
---|
35 | }
|
---|
36 | /* CHBIS (array, char) - Sets bit in char-bit array
|
---|
37 | */
|
---|
38 | chbis(array,c)
|
---|
39 | register int *array, c;
|
---|
40 | { array[c >> CHBBITS] |= (1 << (c & CHBMASK));
|
---|
41 | }
|
---|
42 | /* CHBIC (array, char) - Clears bit in char-bit array
|
---|
43 | */
|
---|
44 | chbic(array,c)
|
---|
45 | register int *array, c;
|
---|
46 | { array[c >> CHBBITS] &= ~(1 << (c & CHBMASK));
|
---|
47 | }
|
---|