Back to index

python3.2  3.2.2
Defines | Typedefs | Functions
bitset.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define BYTE   char
#define testbit(ss, ibit)   (((ss)[BIT2BYTE(ibit)] & BIT2MASK(ibit)) != 0)
#define BITSPERBYTE   (8*sizeof(BYTE))
#define NBYTES(nbits)   (((nbits) + BITSPERBYTE - 1) / BITSPERBYTE)
#define BIT2BYTE(ibit)   ((ibit) / BITSPERBYTE)
#define BIT2SHIFT(ibit)   ((ibit) % BITSPERBYTE)
#define BIT2MASK(ibit)   (1 << BIT2SHIFT(ibit))
#define BYTE2BIT(ibyte)   ((ibyte) * BITSPERBYTE)

Typedefs

typedef BYTEbitset

Functions

bitset newbitset (int nbits)
void delbitset (bitset bs)
int addbit (bitset bs, int ibit)
int samebitset (bitset bs1, bitset bs2, int nbits)
void mergebitset (bitset bs1, bitset bs2, int nbits)

Define Documentation

#define BIT2BYTE (   ibit)    ((ibit) / BITSPERBYTE)

Definition at line 24 of file bitset.h.

#define BIT2MASK (   ibit)    (1 << BIT2SHIFT(ibit))

Definition at line 26 of file bitset.h.

#define BIT2SHIFT (   ibit)    ((ibit) % BITSPERBYTE)

Definition at line 25 of file bitset.h.

#define BITSPERBYTE   (8*sizeof(BYTE))

Definition at line 21 of file bitset.h.

#define BYTE   char

Definition at line 10 of file bitset.h.

#define BYTE2BIT (   ibyte)    ((ibyte) * BITSPERBYTE)

Definition at line 27 of file bitset.h.

#define NBYTES (   nbits)    (((nbits) + BITSPERBYTE - 1) / BITSPERBYTE)

Definition at line 22 of file bitset.h.

#define testbit (   ss,
  ibit 
)    (((ss)[BIT2BYTE(ibit)] & BIT2MASK(ibit)) != 0)

Definition at line 16 of file bitset.h.


Typedef Documentation

typedef BYTE* bitset

Definition at line 12 of file bitset.h.


Function Documentation

int addbit ( bitset  bs,
int  ibit 
)

Definition at line 29 of file bitset.c.

{
    int ibyte = BIT2BYTE(ibit);
    BYTE mask = BIT2MASK(ibit);

    if (ss[ibyte] & mask)
        return 0; /* Bit already set */
    ss[ibyte] |= mask;
    return 1;
}

Definition at line 23 of file bitset.c.

{
    PyObject_FREE(ss);
}
void mergebitset ( bitset  bs1,
bitset  bs2,
int  nbits 
)

Definition at line 60 of file bitset.c.

{
    int i;

    for (i = NBYTES(nbits); --i >= 0; )
        *ss1++ |= *ss2++;
}
bitset newbitset ( int  nbits)

Definition at line 8 of file bitset.c.

{
    int nbytes = NBYTES(nbits);
    bitset ss = (char *)PyObject_MALLOC(sizeof(BYTE) *  nbytes);

    if (ss == NULL)
        Py_FatalError("no mem for bitset");

    ss += nbytes;
    while (--nbytes >= 0)
        *--ss = 0;
    return ss;
}

Here is the call graph for this function:

int samebitset ( bitset  bs1,
bitset  bs2,
int  nbits 
)

Definition at line 49 of file bitset.c.

{
    int i;

    for (i = NBYTES(nbits); --i >= 0; )
        if (*ss1++ != *ss2++)
            return 0;
    return 1;
}