Staging
v0.8.1
Revision 420cca92e8b1b5b9bd2b9a58a93d4e8f0ff86d1d authored by Georg Brandl on 26 November 2010, 07:21:01 UTC, committed by Georg Brandl on 26 November 2010, 07:21:01 UTC
svn+ssh://pythondev@svn.python.org/python/branches/py3k

........
  r85253 | georg.brandl | 2010-10-06 10:52:48 +0200 (Mi, 06 Okt 2010) | 1 line

  Copyedit of os.symlink() docs.
........
  r85452 | georg.brandl | 2010-10-14 08:43:22 +0200 (Do, 14 Okt 2010) | 1 line

  #10046: small correction to atexit docs.
........
  r85453 | georg.brandl | 2010-10-14 08:46:08 +0200 (Do, 14 Okt 2010) | 1 line

  #6825: small correction to split() docs.
........
  r85454 | georg.brandl | 2010-10-14 08:48:47 +0200 (Do, 14 Okt 2010) | 1 line

  Mention 2to3.
........
1 parent c39da79
Raw File
bitset.c

/* Bitset primitives used by the parser generator */

#include "pgenheaders.h"
#include "bitset.h"

bitset
newbitset(int nbits)
{
    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;
}

void
delbitset(bitset ss)
{
    PyObject_FREE(ss);
}

int
addbit(bitset ss, int ibit)
{
    int ibyte = BIT2BYTE(ibit);
    BYTE mask = BIT2MASK(ibit);

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

#if 0 /* Now a macro */
int
testbit(bitset ss, int ibit)
{
    return (ss[BIT2BYTE(ibit)] & BIT2MASK(ibit)) != 0;
}
#endif

int
samebitset(bitset ss1, bitset ss2, int nbits)
{
    int i;

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

void
mergebitset(bitset ss1, bitset ss2, int nbits)
{
    int i;

    for (i = NBYTES(nbits); --i >= 0; )
        *ss1++ |= *ss2++;
}
back to top