#define ABITSET_N_WORDS(N) (((N) + BITSET_WORD_BITS - 1) / BITSET_WORD_BITS)
#define ABITSET_WORDS(X) ((X)->a.words)
-#define ABITSET_N_BITS(X) ((X)->a.n_bits)
-/* Return size in bits of bitset SRC. */
static bitset_bindex
-abitset_size (bitset src)
+abitset_resize (bitset src ATTRIBUTE_UNUSED,
+ bitset_bindex size ATTRIBUTE_UNUSED)
{
- return ABITSET_N_BITS (src);
-}
+ if (BITSET_SIZE_ (src) == size)
+ return size;
+ /* These bitsets have a fixed size. */
+ abort ();
+}
/* Find list of up to NUM bits set in BSET starting from and including
*NEXT and store in array LIST. Return with actual number of bits
if (!word)
return 0;
- size = ABITSET_N_BITS (src);
+ size = BITSET_SIZE_ (src);
bitno = *next;
if (bitno >= size)
return 0;
static void
abitset_set (bitset dst ATTRIBUTE_UNUSED, bitset_bindex bitno ATTRIBUTE_UNUSED)
{
- /* This should never occur for abitsets since we should always
- hit the cache. */
+ /* This should never occur for abitsets since we should always hit
+ the cache. It is likely someone is trying to access outside the
+ bounds of the bitset. */
abort ();
}
abitset_reset (bitset dst ATTRIBUTE_UNUSED,
bitset_bindex bitno ATTRIBUTE_UNUSED)
{
- /* This should never occur for abitsets since we should always
- hit the cache. */
- abort ();
+ /* This should never occur for abitsets since we should always hit
+ the cache. It is likely someone is trying to access outside the
+ bounds of the bitset. Since the bit is zero anyway, let it pass. */
}
{
/* This should never occur for abitsets since we should always
hit the cache. */
- abort ();
return false;
}
unsigned int bitcnt;
bitset_bindex bitoff;
bitset_word *srcp = ABITSET_WORDS (src);
- bitset_bindex n_bits = ABITSET_N_BITS (src);
+ bitset_bindex n_bits = BITSET_SIZE_ (src);
rbitno = *next;
}
else
{
- if (bitno >= ABITSET_N_BITS (src))
+ if (bitno >= BITSET_SIZE_ (src))
return 0;
windex = bitno / BITSET_WORD_BITS;
{
unsigned int last_bit;
- last_bit = ABITSET_N_BITS (dst) % BITSET_WORD_BITS;
+ last_bit = BITSET_SIZE_ (dst) % BITSET_WORD_BITS;
if (last_bit)
ABITSET_WORDS (dst)[dst->b.csize - 1] &=
((bitset_word) 1 << last_bit) - 1;
abitset_reset,
bitset_toggle_,
abitset_test,
- abitset_size,
+ abitset_resize,
+ bitset_size_,
bitset_count_,
abitset_empty_p,
abitset_ones,
abitset_reset,
bitset_toggle_,
abitset_test,
- abitset_size,
+ abitset_resize,
+ bitset_size_,
bitset_count_,
abitset_empty_p,
abitset_ones,
bitset_windex size;
size = ABITSET_N_WORDS (n_bits);
- ABITSET_N_BITS (bset) = n_bits;
+ BITSET_NBITS_ (bset) = n_bits;
/* Use optimized routines if bitset fits within a single word.
There is probably little merit if using caching since
#endif
#include <stdlib.h>
+#include <string.h>
#include "bitset.h"
#include "abitset.h"
#include "lbitset.h"
#include "ebitset.h"
+#include "vbitset.h"
#include "bitset_stats.h"
#include "obstack.h"
bytes = ebitset_bytes (n_bits);
break;
+ case BITSET_VARRAY:
+ bytes = vbitset_bytes (n_bits);
+ break;
+
default:
abort ();
}
case BITSET_TABLE:
return ebitset_init (bset, n_bits);
+ case BITSET_VARRAY:
+ return vbitset_init (bset, n_bits);
+
default:
abort ();
}
enum bitset_type
bitset_type_choose (bitset_bindex n_bits ATTRIBUTE_UNUSED, unsigned int attr)
{
- enum bitset_type type;
-
/* Check attributes. */
if (attr & BITSET_FIXED && attr & BITSET_VARIABLE)
abort ();
if (attr & BITSET_SPARSE && attr & BITSET_DENSE)
abort ();
- /* Choose the type of bitset. Note that sometimes we will be asked
+ /* Choose the type of bitset. Note that sometimes we will be asked
for a zero length fixed size bitset. */
- type = BITSET_ARRAY;
- /* Currently, the simple bitsets do not support a variable size. */
- if (attr & BITSET_VARIABLE || attr & BITSET_SPARSE)
- {
- type = BITSET_LIST;
- if (attr & BITSET_DENSE || attr & BITSET_GREEDY)
- type = BITSET_TABLE;
- }
+
+ /* If no attributes selected, choose a good compromise. */
+ if (!attr)
+ return BITSET_VARRAY;
+
+ if (attr & BITSET_SPARSE)
+ return BITSET_LIST;
+
+ if (attr & BITSET_FIXED)
+ return BITSET_ARRAY;
- return type;
+ if (attr & BITSET_GREEDY)
+ return BITSET_TABLE;
+
+ return BITSET_VARRAY;
}
}
+/* Return true if both bitsets are of the same type and size. */
+extern bool
+bitset_compatible_p (bitset bset1, bitset bset2)
+{
+ return BITSET_COMPATIBLE_ (bset1, bset2);
+}
+
+
/* Find previous bit set in SRC starting from and including BITNO.
Return BITSET_BINDEX_MAX if SRC empty. */
bitset_bindex
}
-
/* Release memory associated with bitsets. */
void
bitset_release_memory (void)
}
-
/* Toggle bit BITNO in bitset BSET and the new value of the bit. */
bool
bitset_toggle_ (bitset bset, bitset_bindex bitno)
}
+/* Return number of bits in bitset SRC. */
+bitset_bindex
+bitset_size_ (bitset src)
+{
+ return BITSET_NBITS_ (src);
+}
+
+
/* Return number of bits set in bitset SRC. */
bitset_bindex
bitset_count_ (bitset src)
/* Bitset statistics.
- Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ Copyright (C) 2002 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
#include "abitset.h"
#include "ebitset.h"
#include "lbitset.h"
+#include "vbitset.h"
#include "bitset_stats.h"
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
+#ifdef HAVE_GETTEXT_H
#include "gettext.h"
#define _(Msgid) gettext (Msgid)
+#else
+#define _(Msgid) Msgid
+#endif
/* Configuration macros. */
#define BITSET_STATS_FILE "bitset.dat"
static bitset_bindex
+bitset_stats_resize (bitset src, bitset_bindex size)
+{
+ return BITSET_RESIZE_ (src->s.bset, size);
+}
+
+
+static bitset_bindex
bitset_stats_size (bitset src)
{
return BITSET_SIZE_ (src->s.bset);
bitset_stats_and_or (bitset dst, bitset src1, bitset src2, bitset src3)
{
BITSET_CHECK4_ (dst, src1, src2, src3);
-
BITSET_AND_OR_ (dst->s.bset, src1->s.bset, src2->s.bset, src3->s.bset);
}
bitset_stats_and_or_cmp (bitset dst, bitset src1, bitset src2, bitset src3)
{
BITSET_CHECK4_ (dst, src1, src2, src3);
-
return BITSET_AND_OR_CMP_ (dst->s.bset, src1->s.bset, src2->s.bset, src3->s.bset);
}
bitset_stats_andn_or (bitset dst, bitset src1, bitset src2, bitset src3)
{
BITSET_CHECK4_ (dst, src1, src2, src3);
-
BITSET_ANDN_OR_ (dst->s.bset, src1->s.bset, src2->s.bset, src3->s.bset);
}
bitset_stats_andn_or_cmp (bitset dst, bitset src1, bitset src2, bitset src3)
{
BITSET_CHECK4_ (dst, src1, src2, src3);
-
return BITSET_ANDN_OR_CMP_ (dst->s.bset, src1->s.bset, src2->s.bset, src3->s.bset);
}
bitset_stats_or_and (bitset dst, bitset src1, bitset src2, bitset src3)
{
BITSET_CHECK4_ (dst, src1, src2, src3);
-
BITSET_OR_AND_ (dst->s.bset, src1->s.bset, src2->s.bset, src3->s.bset);
}
bitset_stats_or_and_cmp (bitset dst, bitset src1, bitset src2, bitset src3)
{
BITSET_CHECK4_ (dst, src1, src2, src3);
-
return BITSET_OR_AND_CMP_ (dst->s.bset, src1->s.bset, src2->s.bset, src3->s.bset);
}
bitset_bindex tmp;
bitset_bindex size;
bitset_bindex i;
+ enum bitset_type type;
count = BITSET_LIST_ (bset->s.bset, list, num, next);
+ type = BITSET_TYPE_ (bset->s.bset);
BITSET_STATS_LISTS_INC (bset->s.bset);
/* Log histogram of number of set bits. */
bitset_stats_reset,
bitset_stats_toggle,
bitset_stats_test,
+ bitset_stats_resize,
bitset_stats_size,
bitset_stats_count,
bitset_stats_empty_p,
bset->b.csize = 0;
bset->b.cdata = 0;
+ BITSET_NBITS_ (bset) = n_bits;
+
/* Set up the actual bitset implementation that
we are a wrapper over. */
switch (type)
ebitset_init (sbset, n_bits);
break;
+ case BITSET_VARRAY:
+ bytes = vbitset_bytes (n_bits);
+ sbset = (bitset) xcalloc (1, bytes);
+ vbitset_init (sbset, n_bits);
+ break;
+
default:
abort ();
}