Ignore bytecode files in importlib.
[python.git] / Parser / bitset.c
blobb5543b81d3a5df6a50842643d2db54688e52af1d
2 /* Bitset primitives used by the parser generator */
4 #include "pgenheaders.h"
5 #include "bitset.h"
7 bitset
8 newbitset(int nbits)
10 int nbytes = NBYTES(nbits);
11 bitset ss = (char *)PyObject_MALLOC(sizeof(BYTE) * nbytes);
13 if (ss == NULL)
14 Py_FatalError("no mem for bitset");
16 ss += nbytes;
17 while (--nbytes >= 0)
18 *--ss = 0;
19 return ss;
22 void
23 delbitset(bitset ss)
25 PyObject_FREE(ss);
28 int
29 addbit(bitset ss, int ibit)
31 int ibyte = BIT2BYTE(ibit);
32 BYTE mask = BIT2MASK(ibit);
34 if (ss[ibyte] & mask)
35 return 0; /* Bit already set */
36 ss[ibyte] |= mask;
37 return 1;
40 #if 0 /* Now a macro */
41 int
42 testbit(bitset ss, int ibit)
44 return (ss[BIT2BYTE(ibit)] & BIT2MASK(ibit)) != 0;
46 #endif
48 int
49 samebitset(bitset ss1, bitset ss2, int nbits)
51 int i;
53 for (i = NBYTES(nbits); --i >= 0; )
54 if (*ss1++ != *ss2++)
55 return 0;
56 return 1;
59 void
60 mergebitset(bitset ss1, bitset ss2, int nbits)
62 int i;
64 for (i = NBYTES(nbits); --i >= 0; )
65 *ss1++ |= *ss2++;