1 /* A simple, memory-efficient bitset implementation.
3 Copyright (C) 2009 Free Software Foundation, Inc.
5 This file is part of Bison, the GNU Compiler Compiler.
7 This program is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
26 Sbitset__new (Sbitset__Index nbits
)
28 /* Some functions, like Sbitset__last_byte_mask, will fail if nbits = 0. */
30 return xcalloc (1, Sbitset__nbytes (nbits
));
34 Sbitset__new_on_obstack (Sbitset__Index nbits
, struct obstack
*obstackp
)
40 result
= obstack_alloc (obstackp
, Sbitset__nbytes (nbits
));
41 for (ptr
= result
, end
= result
+ Sbitset__nbytes (nbits
); ptr
< end
; ++ptr
)
47 Sbitset__delete (Sbitset self
)
53 Sbitset__isEmpty (Sbitset self
, Sbitset__Index nbits
)
55 Sbitset last
= self
+ Sbitset__nbytes (nbits
) - 1;
56 for (; self
< last
; ++self
)
59 return ((*last
) & Sbitset__last_byte_mask (nbits
)) == 0;
63 Sbitset__fprint(Sbitset self
, Sbitset__Index nbits
, FILE *file
)
69 "nbits = %" SBITSET__INDEX__CONVERSION_SPEC
", set = {",
71 SBITSET__FOR_EACH (self
, nbits
, itr
, i
)
77 fprintf (file
, " %" SBITSET__INDEX__CONVERSION_SPEC
, i
);