Back to index

python3.2  3.2.2
Functions
bitset.c File Reference
#include "pgenheaders.h"
#include "bitset.h"

Go to the source code of this file.

Functions

bitset newbitset (int nbits)
void delbitset (bitset ss)
int addbit (bitset ss, int ibit)
int samebitset (bitset ss1, bitset ss2, int nbits)
void mergebitset (bitset ss1, bitset ss2, int nbits)

Function Documentation

int addbit ( bitset  ss,
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  ss1,
bitset  ss2,
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  ss1,
bitset  ss2,
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;
}