Commit | Line | Data |
---|---|---|
86530b38 AT |
1 | #ifndef Py_BITSET_H |
2 | #define Py_BITSET_H | |
3 | #ifdef __cplusplus | |
4 | extern "C" { | |
5 | #endif | |
6 | ||
7 | /* Bitset interface */ | |
8 | ||
9 | #define BYTE char | |
10 | ||
11 | typedef BYTE *bitset; | |
12 | ||
13 | bitset newbitset(int nbits); | |
14 | void delbitset(bitset bs); | |
15 | #define testbit(ss, ibit) (((ss)[BIT2BYTE(ibit)] & BIT2MASK(ibit)) != 0) | |
16 | int addbit(bitset bs, int ibit); /* Returns 0 if already set */ | |
17 | int samebitset(bitset bs1, bitset bs2, int nbits); | |
18 | void mergebitset(bitset bs1, bitset bs2, int nbits); | |
19 | ||
20 | #define BITSPERBYTE (8*sizeof(BYTE)) | |
21 | #define NBYTES(nbits) (((nbits) + BITSPERBYTE - 1) / BITSPERBYTE) | |
22 | ||
23 | #define BIT2BYTE(ibit) ((ibit) / BITSPERBYTE) | |
24 | #define BIT2SHIFT(ibit) ((ibit) % BITSPERBYTE) | |
25 | #define BIT2MASK(ibit) (1 << BIT2SHIFT(ibit)) | |
26 | #define BYTE2BIT(ibyte) ((ibyte) * BITSPERBYTE) | |
27 | ||
28 | #ifdef __cplusplus | |
29 | } | |
30 | #endif | |
31 | #endif /* !Py_BITSET_H */ |