blob: b22fa77815cfb8316fedbfff50c2de5074f9ed64 [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
Serhiy Storchaka598ceae2017-11-28 17:56:10 +020010#define BYTE char
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000011
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
Serhiy Storchaka598ceae2017-11-28 17:56:10 +020021#define BITSPERBYTE (8*sizeof(BYTE))
22#define NBYTES(nbits) (((nbits) + BITSPERBYTE - 1) / BITSPERBYTE)
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000023
Serhiy Storchaka598ceae2017-11-28 17:56:10 +020024#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 Rossum85a5fbb1990-10-14 12:07:46 +000028
Guido van Rossuma3309961993-07-28 09:05:47 +000029#ifdef __cplusplus
30}
31#endif
32#endif /* !Py_BITSET_H */