This commit is contained in:
Paul Eggert
2003-06-07 23:28:20 +00:00
parent 58f5a6af40
commit 7347b2d316

View File

@@ -1,19 +1,20 @@
/* Generic bitsets.
Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
Copyright (C) 2002, 2003 Free Software Foundation, Inc.
Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz).
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#ifndef _BITSET_H
#define _BITSET_H
@@ -22,12 +23,18 @@
Only use the functions and macros defined in this file. */
#include "bbitset.h"
#include "obstack.h"
#include <stdio.h>
#if USE_UNLOCKED_IO
# include "unlocked-io.h"
/* obstack.h tries to be portable to K&R compilers, but its
__INT_TO_PTR macro generates diagnostics on compilers like Tru64 cc
that define __STDC__ to 0 when not in strict ANSI mode. The bitset
code assumes C89 or later, so it can avoid these glitches by
defining __INT_TO_PTR appropriately for C89 or later. */
#ifndef __INT_TO_PTR
# define __INT_TO_PTR(P) ((void *) ((P) + (char *) 0))
#endif
#include "obstack.h"
#include <stdio.h>
/* Attributes used to select a bitset implementation. */
enum bitset_attr {BITSET_FIXED = 1, /* Bitset size fixed. */
@@ -96,37 +103,38 @@ typedef struct
/* Return bytes required for bitset of desired type and size. */
extern size_t bitset_bytes (enum bitset_type, bitset_bindex);
extern size_t bitset_bytes PARAMS ((enum bitset_type, bitset_bindex));
/* Initialise a bitset with desired type and size. */
extern bitset bitset_init (bitset, bitset_bindex, enum bitset_type);
extern bitset bitset_init PARAMS ((bitset, bitset_bindex, enum bitset_type));
/* Select an implementation type based on the desired bitset size
and attributes. */
extern enum bitset_type bitset_type_choose (bitset_bindex, bitset_attrs);
extern enum bitset_type bitset_type_choose PARAMS ((bitset_bindex,
bitset_attrs));
/* Create a bitset of desired type and size. The bitset is zeroed. */
extern bitset bitset_alloc (bitset_bindex, enum bitset_type);
extern bitset bitset_alloc PARAMS ((bitset_bindex, enum bitset_type));
/* Free bitset. */
extern void bitset_free (bitset);
extern void bitset_free PARAMS ((bitset));
/* Create a bitset of desired type and size using an obstack. The
bitset is zeroed. */
extern bitset bitset_obstack_alloc (struct obstack *bobstack,
bitset_bindex, enum bitset_type);
extern bitset bitset_obstack_alloc PARAMS ((struct obstack *bobstack,
bitset_bindex, enum bitset_type));
/* Free bitset allocated on obstack. */
extern void bitset_obstack_free (bitset);
extern void bitset_obstack_free PARAMS ((bitset));
/* Create a bitset of desired size and attributes. The bitset is zeroed. */
extern bitset bitset_create (bitset_bindex, bitset_attrs);
extern bitset bitset_create PARAMS ((bitset_bindex, bitset_attrs));
/* Return bitset type. */
extern enum bitset_type bitset_type_get (bitset);
extern enum bitset_type bitset_type_get PARAMS ((bitset));
/* Return bitset type name. */
extern const char *bitset_type_name_get (bitset);
extern const char *bitset_type_name_get PARAMS ((bitset));
/* Set bit BITNO in bitset BSET. */
@@ -178,7 +186,7 @@ bitset_test (bitset bset, bitset_bindex bitno)
#define bitset_size(SRC) BITSET_SIZE_ (SRC)
/* Change size of bitset. */
extern void bitset_resize (bitset, bitset_bindex);
extern void bitset_resize PARAMS ((bitset, bitset_bindex));
/* Return number of bits set in bitset SRC. */
#define bitset_count(SRC) BITSET_COUNT_ (SRC)
@@ -278,42 +286,43 @@ extern void bitset_resize (bitset, bitset_bindex);
BITSET_LIST_REVERSE_ (BSET, LIST, NUM, NEXT)
/* Return true if both bitsets are of the same type and size. */
extern bool bitset_compatible_p (bitset bset1, bitset bset2);
extern bool
bitset_compatible_p (bitset bset1, bitset bset2);
/* Find next set bit from the given bit index. */
extern bitset_bindex bitset_next (bitset, bitset_bindex);
extern bitset_bindex bitset_next PARAMS ((bitset, bitset_bindex));
/* Find previous set bit from the given bit index. */
extern bitset_bindex bitset_prev (bitset, bitset_bindex);
extern bitset_bindex bitset_prev PARAMS ((bitset, bitset_bindex));
/* Find first set bit. */
extern bitset_bindex bitset_first (bitset);
extern bitset_bindex bitset_first PARAMS ((bitset));
/* Find last set bit. */
extern bitset_bindex bitset_last (bitset);
extern bitset_bindex bitset_last PARAMS ((bitset));
/* Return nonzero if this is the only set bit. */
extern bool bitset_only_set_p (bitset, bitset_bindex);
extern bool bitset_only_set_p PARAMS ((bitset, bitset_bindex));
/* Dump bitset. */
extern void bitset_dump (FILE *, bitset);
extern void bitset_dump PARAMS ((FILE *, bitset));
/* Loop over all elements of BSET, starting with MIN, setting INDEX
to the index of each set bit. For example, the following will print
the bits set in a bitset:
bitset_bindex i;
bitset_bindex index;
bitset_iterator iter;
BITSET_FOR_EACH (iter, src, i, 0)
BITSET_FOR_EACH (iter, src, index, 0)
{
printf ("%lu ", (unsigned long int) i);
printf ("%ld ", index);
};
*/
#define BITSET_FOR_EACH(ITER, BSET, INDEX, MIN) \
for (ITER.next = (MIN), ITER.num = BITSET_LIST_SIZE; \
(ITER.num == BITSET_LIST_SIZE) \
&& (ITER.num = bitset_list (BSET, ITER.list, \
(ITER.num == BITSET_LIST_SIZE) \
&& (ITER.num = bitset_list (BSET, ITER.list, \
BITSET_LIST_SIZE, &ITER.next));) \
for (ITER.i = 0; \
ITER.i < ITER.num && ((INDEX) = ITER.list[ITER.i], 1); \
@@ -321,20 +330,20 @@ extern void bitset_dump (FILE *, bitset);
/* Loop over all elements of BSET, in reverse order starting with
MIN, setting INDEX to the index of each set bit. For example, the
MIN, setting INDEX to the index of each set bit. For example, the
following will print the bits set in a bitset in reverse order:
bitset_bindex i;
bitset_bindex index;
bitset_iterator iter;
BITSET_FOR_EACH_REVERSE (iter, src, i, 0)
BITSET_FOR_EACH_REVERSE (iter, src, index, 0)
{
printf ("%lu ", (unsigned long int) i);
printf ("%ld ", index);
};
*/
#define BITSET_FOR_EACH_REVERSE(ITER, BSET, INDEX, MIN) \
for (ITER.next = (MIN), ITER.num = BITSET_LIST_SIZE; \
(ITER.num == BITSET_LIST_SIZE) \
(ITER.num == BITSET_LIST_SIZE) \
&& (ITER.num = bitset_list_reverse (BSET, ITER.list, \
BITSET_LIST_SIZE, &ITER.next));) \
for (ITER.i = 0; \
@@ -365,27 +374,28 @@ extern void bitset_dump (FILE *, bitset);
/* Release any memory tied up with bitsets. */
extern void bitset_release_memory (void);
extern void bitset_release_memory PARAMS ((void));
/* Enable bitset stats gathering. */
extern void bitset_stats_enable (void);
extern void bitset_stats_enable PARAMS ((void));
/* Disable bitset stats gathering. */
extern void bitset_stats_disable (void);
extern void bitset_stats_disable PARAMS ((void));
/* Read bitset stats file of accummulated stats. */
void bitset_stats_read (const char *file_name);
void bitset_stats_read PARAMS ((const char *filename));
/* Write bitset stats file of accummulated stats. */
void bitset_stats_write (const char *file_name);
void bitset_stats_write PARAMS ((const char *filename));
/* Dump bitset stats. */
extern void bitset_stats_dump (FILE *);
extern void bitset_stats_dump PARAMS ((FILE *));
/* Function to debug bitset from debugger. */
extern void debug_bitset (bitset);
extern void debug_bitset PARAMS ((bitset));
/* Function to debug bitset stats from debugger. */
extern void debug_bitset_stats (void);
extern void debug_bitset_stats PARAMS ((void));
#endif /* _BITSET_H */