Mercurial > cpython-lru_cache-weakref
annotate Parser/bitset.c @ 3720:b341def4eef8 legacy-trunk
Ignore latex intermediate products.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Wed, 26 Jun 1996 19:30:01 +0000 |
| parents | 146890653a57 |
| children | 65d2d8e67da3 |
| rev | line source |
|---|---|
| 145 | 1 /*********************************************************** |
|
2060
146890653a57
Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents:
1848
diff
changeset
|
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, |
|
146890653a57
Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents:
1848
diff
changeset
|
3 The Netherlands. |
| 145 | 4 |
| 5 All Rights Reserved | |
| 6 | |
| 7 Permission to use, copy, modify, and distribute this software and its | |
| 8 documentation for any purpose and without fee is hereby granted, | |
| 9 provided that the above copyright notice appear in all copies and that | |
| 10 both that copyright notice and this permission notice appear in | |
| 11 supporting documentation, and that the names of Stichting Mathematisch | |
| 12 Centrum or CWI not be used in advertising or publicity pertaining to | |
| 13 distribution of the software without specific, written prior permission. | |
| 14 | |
| 15 STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO | |
| 16 THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND | |
| 17 FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE | |
| 18 FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
| 19 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
| 20 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT | |
| 21 OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
| 22 | |
| 23 ******************************************************************/ | |
| 24 | |
| 86 | 25 /* Bitset primitives used by the parser generator */ |
| 6 | 26 |
| 86 | 27 #include "pgenheaders.h" |
| 6 | 28 #include "bitset.h" |
| 29 | |
| 30 bitset | |
| 31 newbitset(nbits) | |
| 32 int nbits; | |
| 33 { | |
| 34 int nbytes = NBYTES(nbits); | |
| 35 bitset ss = NEW(BYTE, nbytes); | |
| 36 | |
| 37 if (ss == NULL) | |
| 38 fatal("no mem for bitset"); | |
| 39 | |
| 40 ss += nbytes; | |
| 41 while (--nbytes >= 0) | |
| 42 *--ss = 0; | |
| 43 return ss; | |
| 44 } | |
| 45 | |
| 46 void | |
| 47 delbitset(ss) | |
| 48 bitset ss; | |
| 49 { | |
| 50 DEL(ss); | |
| 51 } | |
| 52 | |
| 53 int | |
| 54 addbit(ss, ibit) | |
| 55 bitset ss; | |
| 56 int ibit; | |
| 57 { | |
| 58 int ibyte = BIT2BYTE(ibit); | |
| 59 BYTE mask = BIT2MASK(ibit); | |
| 60 | |
| 61 if (ss[ibyte] & mask) | |
| 62 return 0; /* Bit already set */ | |
| 63 ss[ibyte] |= mask; | |
| 64 return 1; | |
| 65 } | |
| 66 | |
| 67 #if 0 /* Now a macro */ | |
| 68 int | |
| 69 testbit(ss, ibit) | |
| 70 bitset ss; | |
| 71 int ibit; | |
| 72 { | |
| 73 return (ss[BIT2BYTE(ibit)] & BIT2MASK(ibit)) != 0; | |
| 74 } | |
| 75 #endif | |
| 76 | |
| 77 int | |
| 78 samebitset(ss1, ss2, nbits) | |
| 79 bitset ss1, ss2; | |
| 80 int nbits; | |
| 81 { | |
| 82 int i; | |
| 83 | |
| 84 for (i = NBYTES(nbits); --i >= 0; ) | |
| 85 if (*ss1++ != *ss2++) | |
| 86 return 0; | |
| 87 return 1; | |
| 88 } | |
| 89 | |
| 90 void | |
| 91 mergebitset(ss1, ss2, nbits) | |
| 92 bitset ss1, ss2; | |
| 93 int nbits; | |
| 94 { | |
| 95 int i; | |
| 96 | |
| 97 for (i = NBYTES(nbits); --i >= 0; ) | |
| 98 *ss1++ |= *ss2++; | |
| 99 } |
