* lib/bitset.c, lib/bitset.h, lib/bitsetv.c, lib/bitsetv.h,

* lib/ebitset.c, lib/ebitset.h, lib/lbitset.c, lib/lbitset.h,
* lib/sbitset.c, lib/sbitset.h, lib/bbitset.h: Update from the
latest sources from Michael.
This commit is contained in:
Akim Demaille
2002-03-04 12:07:08 +00:00
parent 7651439487
commit ef01750240
13 changed files with 1288 additions and 962 deletions

View File

@@ -19,42 +19,14 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#ifndef _BITSET_H
#define _BITSET_H
#if HAVE_CONFIG_H
# include <config.h>
#endif
/* This file is the public interface to the bitset abstract data type.
Only use the functions and macros defined in this file. */
#define BITSET_STATS 1
# ifndef PARAMS
# if defined PROTOTYPES || (defined __STDC__ && __STDC__)
# define PARAMS(Args) Args
# else
# define PARAMS(Args) ()
# endif
# endif
# ifndef __attribute__
# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8) || __STRICT_ANSI__
# define __attribute__(x)
# endif
# endif
# ifndef ATTRIBUTE_NORETURN
# define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
# endif
# ifndef ATTRIBUTE_UNUSED
# define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
# endif
#include "bitset-int.h"
#include "sbitset.h"
#include "lbitset.h"
#include "ebitset.h"
#include "bbitset.h"
#include "obstack.h"
#include <stdio.h>
#include "xalloc.h"
/* Attributes used to select a bitset implementation. */
enum bitset_attr {BITSET_FIXED = 1, /* Bitset size fixed. */
BITSET_VARIABLE = 2, /* Bitset size variable. */
BITSET_DENSE = 4, /* Bitset dense. */
@@ -64,75 +36,48 @@ enum bitset_attr {BITSET_FIXED = 1, /* Bitset size fixed. */
typedef unsigned int bitset_attrs;
/* The elements of these structures should be considered
to be private. */
typedef struct bitset_struct
/* The contents of the structure should be considered to be private.
While I would like to make this structure opaque, it needs to be
visible for the inline bit set/test functions. */
struct bitset_struct
{
struct bitset_ops_struct *ops;
bitset_windex cindex; /* Cache word index. */
bitset_windex csize; /* Cache size in words. */
bitset_word *cdata; /* Cache data pointer. */
union bitset_data
{
struct sbitset_struct s;
struct lbitset_struct l;
struct ebitset_struct e;
} u;
} *bitset;
/* The contents of this structure should be considered private. */
struct bitset_ops_struct
{
void (*set) PARAMS ((struct bitset_struct *, bitset_bindex));
void (*reset) PARAMS ((struct bitset_struct *, bitset_bindex));
int (*test) PARAMS ((struct bitset_struct *, bitset_bindex));
int (*size) PARAMS ((struct bitset_struct *));
int (*op1) PARAMS ((struct bitset_struct *, enum bitset_ops));
int (*op2) PARAMS ((struct bitset_struct *, struct bitset_struct *,
enum bitset_ops));
int (*op3) PARAMS ((struct bitset_struct *, struct bitset_struct *,
struct bitset_struct *, enum bitset_ops));
int (*op4) PARAMS ((struct bitset_struct *, struct bitset_struct *,
struct bitset_struct *, struct bitset_struct *,
enum bitset_ops));
int (*list) PARAMS ((struct bitset_struct *, bitset_bindex *,
bitset_bindex, bitset_bindex *));
int (*reverse_list) PARAMS ((struct bitset_struct *, bitset_bindex *,
bitset_bindex, bitset_bindex *));
void (*free) PARAMS ((struct bitset_struct *));
enum bitset_type type;
struct bbitset_struct b;
};
/* Return bytes required for bitset of desired type and size. */
extern int bitset_bytes PARAMS ((enum bitset_type, bitset_bindex));
/* Initialise a bitset with desired type and size. */
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 PARAMS ((bitset_bindex,
bitset_attrs));
/* Create a bitset of desired type and size. */
/* Create a bitset of desired type and size. The bitset is zeroed. */
extern bitset bitset_alloc PARAMS ((bitset_bindex, enum bitset_type));
/* Free bitset. */
extern void bitset_free PARAMS ((bitset));
/* Create a bitset of desired type and size using obstack. */
/* Create a bitset of desired type and size using an obstack. The
bitset is zeroed. */
extern bitset bitset_obstack_alloc PARAMS ((struct obstack *bobstack,
bitset_bindex, enum bitset_type));
/* Free bitset allocated on obstack. */
extern void bitset_obstack_free PARAMS ((bitset));
/* Create a bitset of desired size and attributes. */
/* Create a bitset of desired size and attributes. The bitset is zeroed. */
extern bitset bitset_create PARAMS ((bitset_bindex, bitset_attrs));
/* Return size in bits of bitset SRC. */
extern int bitset_size PARAMS ((bitset));
/* Return number of bits set in bitset SRC. */
extern int bitset_count PARAMS ((bitset));
#if BITSET_CACHE && BITSET_INLINE
static inline void bitset_set PARAMS ((bitset, bitset_bindex));
static inline void bitset_reset PARAMS ((bitset, bitset_bindex));
@@ -144,12 +89,12 @@ static inline void bitset_set (bset, bitno)
bitset_bindex bitno;
{
bitset_windex index = bitno / BITSET_WORD_BITS;
bitset_windex offset = index - bset->cindex;
bitset_windex offset = index - bset->b.cindex;
if (offset < bset->csize)
bset->cdata[offset] |= (1 << (bitno % BITSET_WORD_BITS));
if (offset < bset->b.csize)
bset->b.cdata[offset] |= (1 << (bitno % BITSET_WORD_BITS));
else
BITSET__SET (bset, bitno);
BITSET_SET_ (bset, bitno);
}
@@ -159,12 +104,12 @@ static inline void bitset_reset (bset, bitno)
bitset_bindex bitno;
{
bitset_windex index = bitno / BITSET_WORD_BITS;
bitset_windex offset = index - bset->cindex;
bitset_windex offset = index - bset->b.cindex;
if (offset < bset->csize)
bset->cdata[offset] &= ~(1 << (bitno % BITSET_WORD_BITS));
if (offset < bset->b.csize)
bset->b.cdata[offset] &= ~(1 << (bitno % BITSET_WORD_BITS));
else
BITSET__RESET (bset, bitno);
BITSET_RESET_ (bset, bitno);
}
@@ -174,12 +119,12 @@ static inline int bitset_test (bset, bitno)
bitset_bindex bitno;
{
bitset_windex index = bitno / BITSET_WORD_BITS;
bitset_windex offset = index - bset->cindex;
bitset_windex offset = index - bset->b.cindex;
if (offset < bset->csize)
return (bset->cdata[offset] >> (bitno % BITSET_WORD_BITS)) & 1;
if (offset < bset->b.csize)
return (bset->b.cdata[offset] >> (bitno % BITSET_WORD_BITS)) & 1;
else
return BITSET__TEST (bset, bitno);
return BITSET_TEST_ (bset, bitno);
}
#endif
@@ -191,12 +136,12 @@ do \
{ \
bitset_bindex _bitno = (bitno); \
bitset_windex _index = _bitno / BITSET_WORD_BITS; \
bitset_windex _offset = _index - (bset)->cindex; \
bitset_windex _offset = _index - (bset)->b.cindex; \
\
if (_offset < (bset)->csize) \
(bset)->cdata[_offset] |= (1 << (_bitno % BITSET_WORD_BITS)); \
if (_offset < (bset)->b.csize) \
(bset)->b.cdata[_offset] |= (1 << (_bitno % BITSET_WORD_BITS)); \
else \
BITSET__SET ((bset), _bitno); \
BITSET_SET_ ((bset), _bitno); \
} while (0)
@@ -206,32 +151,32 @@ do \
{ \
bitset_bindex _bitno = (bitno); \
bitset_windex _index = _bitno / BITSET_WORD_BITS; \
bitset_windex _offset = _index - (bset)->cindex; \
bitset_windex _offset = _index - (bset)->b.cindex; \
\
if (_offset < (bset)->csize) \
(bset)->cdata[_offset] &= ~(1 << (_bitno % BITSET_WORD_BITS)); \
if (_offset < (bset)->b.csize) \
(bset)->b.cdata[_offset] &= ~(1 << (_bitno % BITSET_WORD_BITS)); \
else \
BITSET__RESET ((bset), _bitno); \
BITSET_RESET_ ((bset), _bitno); \
} while (0)
/* Test bit BITNO in bitset BSET. */
#define bitset_test(bset, bitno) \
(((((bitno) / BITSET_WORD_BITS) - (bset)->cindex) < (bset)->csize) \
? ((bset)->cdata[(((bitno) / BITSET_WORD_BITS) - (bset)->cindex)] \
(((((bitno) / BITSET_WORD_BITS) - (bset)->b.cindex) < (bset)->b.csize) \
? ((bset)->b.cdata[(((bitno) / BITSET_WORD_BITS) - (bset)->b.cindex)] \
>> ((bitno) % BITSET_WORD_BITS)) & 1 \
: (unsigned int) BITSET__TEST ((bset), (bitno)))
: (unsigned int) BITSET_TEST_ ((bset), (bitno)))
#endif
#if ! BITSET_CACHE
/* Set bit BITNO in bitset SRC. */
#define bitset_set(SRC, BITNO) BITSET__SET (SRC, BITNO)
#define bitset_set(SRC, BITNO) BITSET_SET_ (SRC, BITNO)
/* Reset bit BITNO in bitset SRC. */
#define bitset_reset(SRC, BITNO) BITSET__RESET (SRC, BITNO)
#define bitset_reset(SRC, BITNO) BITSET_RESET_ (SRC, BITNO)
/* Return non-zero if bit BITNO in bitset SRC is set. */
#define bitset_test(SRC, BITNO) BITSET__TEST (SRC, BITNO)
#define bitset_test(SRC, BITNO) BITSET_TEST_ (SRC, BITNO)
#endif
/* DST = 0. */
@@ -249,6 +194,9 @@ extern int bitset_subset_p PARAMS ((bitset, bitset));
/* Return DST == SRC. */
extern int bitset_equal_p PARAMS ((bitset, bitset));
/* Return DST & SRC == 0. */
extern int bitset_disjoint_p PARAMS ((bitset, bitset));
/* DST == SRC. */
extern int bitset_copy PARAMS ((bitset, bitset));
@@ -280,7 +228,7 @@ extern int bitset_and_or PARAMS ((bitset, bitset, bitset, bitset));
/* DST = (SRC1 & ~SRC2) | SRC3. Return non-zero if
DST != (SRC1 & ~SRC2) | SRC3. */
#define bitset_andn_or(DST, SRC1, SRC2, SRC3) \
extern int bitset_andn_or PARAMS ((bitset, bitset, bitset, bitset));
/* Find next bit set in BSET starting from and including BITNO. */
extern int bitset_next PARAMS ((bitset, bitset_bindex));
@@ -296,14 +244,14 @@ extern int bitset_list PARAMS ((bitset, bitset_bindex *, bitset_bindex,
bitset_bindex *));
#else
#define bitset_list(BSET, LIST, NUM, NEXT) \
BITSET__LIST (BSET, LIST, NUM, NEXT)
BITSET_LIST_ (BSET, LIST, NUM, NEXT)
#endif
/* Find reverse list of up to NUM bits set in BSET starting from and
including NEXT. Return with actual number of bits found and with
*NEXT indicating where search stopped. */
#define bitset_reverse_list(BSET, LIST, NUM, NEXT) \
BITSET__REVERSE_LIST (BSET, LIST, NUM, NEXT)
BITSET_REVERSE_LIST_ (BSET, LIST, NUM, NEXT)
/* Find first set bit. */
extern int bitset_first PARAMS ((bitset));
@@ -360,7 +308,7 @@ do { \
} while (0)
/* Define set operations in terms of bit operations. */
/* Define set operations in terms of logical operations. */
#define bitset_diff(DST, SRC1, SRC2) bitset_andn (DST, SRC1, SRC2)
@@ -369,7 +317,8 @@ do { \
#define bitset_union(DST, SRC1, SRC2) bitset_or (DST, SRC1, SRC2)
#define bitset_diff_union(DST, SRC1, SRC2, SRC3) \
bitset_andn_or (DST, SRC1, SRC2, SRC3)
bitset_andn_or (DST, SRC1, SRC2, SRC3)
/* Release any memory tied up with bitsets. */
extern void bitset_release_memory PARAMS ((void));
@@ -386,10 +335,4 @@ extern void debug_bitset PARAMS ((bitset));
/* Function to debug bitset stats from debugger. */
extern void debug_bitset_stats PARAMS ((void));
extern bitset sbitset_init PARAMS ((bitset, bitset_bindex));
extern bitset lbitset_init PARAMS ((bitset, bitset_bindex));
extern bitset ebitset_init PARAMS ((bitset, bitset_bindex));
#endif /* _BITSET_H */