blob: faeb41913df31f995d772b211fd05e5f65196bf8 [file] [log] [blame]
Guido van Rossumf70e43a1991-02-19 12:39:46 +00001
Fred Drake5eb6d4e2000-07-08 23:37:28 +00002#ifndef Py_BITSET_H
3#define Py_BITSET_H
4#ifdef __cplusplus
5extern "C" {
6#endif
7
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00008/* Bitset interface */
9
10#define BYTE char
11
12typedef BYTE *bitset;
13
Fred Drake5eb6d4e2000-07-08 23:37:28 +000014bitset newbitset(int nbits);
15void delbitset(bitset bs);
Guido van Rossum66cb3111994-12-30 15:33:50 +000016#define testbit(ss, ibit) (((ss)[BIT2BYTE(ibit)] & BIT2MASK(ibit)) != 0)
Fred Drake5eb6d4e2000-07-08 23:37:28 +000017int addbit(bitset bs, int ibit); /* Returns 0 if already set */
18int samebitset(bitset bs1, bitset bs2, int nbits);
19void mergebitset(bitset bs1, bitset bs2, int nbits);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000020
21#define BITSPERBYTE (8*sizeof(BYTE))
22#define NBYTES(nbits) (((nbits) + BITSPERBYTE - 1) / BITSPERBYTE)
23
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)
28
Guido van Rossuma3309961993-07-28 09:05:47 +000029#ifdef __cplusplus
30}
31#endif
32#endif /* !Py_BITSET_H */