Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 1 | |
Fred Drake | 5eb6d4e | 2000-07-08 23:37:28 +0000 | [diff] [blame] | 2 | #ifndef Py_BITSET_H |
| 3 | #define Py_BITSET_H |
| 4 | #ifdef __cplusplus |
| 5 | extern "C" { |
| 6 | #endif |
| 7 | |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 8 | /* Bitset interface */ |
| 9 | |
Serhiy Storchaka | 598ceae | 2017-11-28 17:56:10 +0200 | [diff] [blame] | 10 | #define BYTE char |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 11 | |
| 12 | typedef BYTE *bitset; |
| 13 | |
Fred Drake | 5eb6d4e | 2000-07-08 23:37:28 +0000 | [diff] [blame] | 14 | bitset newbitset(int nbits); |
| 15 | void delbitset(bitset bs); |
Guido van Rossum | 66cb311 | 1994-12-30 15:33:50 +0000 | [diff] [blame] | 16 | #define testbit(ss, ibit) (((ss)[BIT2BYTE(ibit)] & BIT2MASK(ibit)) != 0) |
Fred Drake | 5eb6d4e | 2000-07-08 23:37:28 +0000 | [diff] [blame] | 17 | int addbit(bitset bs, int ibit); /* Returns 0 if already set */ |
| 18 | int samebitset(bitset bs1, bitset bs2, int nbits); |
| 19 | void mergebitset(bitset bs1, bitset bs2, int nbits); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 20 | |
Serhiy Storchaka | 598ceae | 2017-11-28 17:56:10 +0200 | [diff] [blame] | 21 | #define BITSPERBYTE (8*sizeof(BYTE)) |
| 22 | #define NBYTES(nbits) (((nbits) + BITSPERBYTE - 1) / BITSPERBYTE) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 23 | |
Serhiy Storchaka | 598ceae | 2017-11-28 17:56:10 +0200 | [diff] [blame] | 24 | #define BIT2BYTE(ibit) ((ibit) / BITSPERBYTE) |
| 25 | #define BIT2SHIFT(ibit) ((ibit) % BITSPERBYTE) |
| 26 | #define BIT2MASK(ibit) (1 << BIT2SHIFT(ibit)) |
| 27 | #define BYTE2BIT(ibyte) ((ibyte) * BITSPERBYTE) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 28 | |
Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 29 | #ifdef __cplusplus |
| 30 | } |
| 31 | #endif |
| 32 | #endif /* !Py_BITSET_H */ |