/* Bitset statistics.
- Copyright (C) 2002 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2003, 2004, 2005 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
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.
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/* This file is a wrapper bitset implementation for the other bitset
#include "abitset.h"
#include "ebitset.h"
#include "lbitset.h"
+#include "vbitset.h"
#include "bitset_stats.h"
#include <stdlib.h>
#include <string.h>
struct bitset_stats_info_struct bitset_stats_info_data;
struct bitset_stats_info_struct *bitset_stats_info;
-int bitset_stats_enabled = 0;
+bool bitset_stats_enabled = false;
/* Print a percentage histogram with message MSG to FILE. */
for (; i < n_bins; i++)
fprintf (file, "%*lu-%lu\t%8u (%5.1f%%)\n",
max_width - ((unsigned int) (0.30103 * (i) + 0.9999) + 1),
- (unsigned long) 1 << (i - 1),
- ((unsigned long) 1 << i) - 1,
+ 1UL << (i - 1),
+ (1UL << i) - 1,
bins[i],
(100.0 * bins[i]) / total);
}
/* Print all bitset statistics to FILE. */
static void
-bitset_stats_print (FILE *file, int verbose ATTRIBUTE_UNUSED)
+bitset_stats_print (FILE *file, bool verbose ATTRIBUTE_UNUSED)
{
int i;
{
if (!bitset_stats_info)
bitset_stats_info = &bitset_stats_info_data;
- bitset_stats_enabled = 1;
+ bitset_stats_enabled = true;
}
void
bitset_stats_disable (void)
{
- bitset_stats_enabled = 0;
+ bitset_stats_enabled = false;
}
else
fprintf (stderr, _("Bad stats file size.\n"));
}
- fclose (file);
+ if (fclose (file) != 0)
+ perror (_("Could not read stats file."));
}
bitset_stats_info_data.runs++;
}
if (fwrite (&bitset_stats_info_data, sizeof (bitset_stats_info_data),
1, file) != 1)
perror (_("Could not write stats file."));
- fclose (file);
+ if (fclose (file) != 0)
+ perror (_("Could not write stats file."));
}
else
perror (_("Could not open stats file for writing."));
void
bitset_stats_dump (FILE *file)
{
- bitset_stats_print (file, 0);
+ bitset_stats_print (file, false);
}
void
debug_bitset_stats (void)
{
- bitset_stats_print (stderr, 1);
+ bitset_stats_print (stderr, true);
}
}
-static int
+static bool
bitset_stats_toggle (bitset src, bitset_bindex bitno)
{
return BITSET_TOGGLE_ (src->s.bset, bitno);
}
-static int
+static bool
bitset_stats_test (bitset src, bitset_bindex bitno)
{
bitset bset = src->s.bset;
}
+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)
{
}
-static int
+static bool
bitset_stats_empty_p (bitset dst)
{
return BITSET_EMPTY_P_ (dst->s.bset);
}
-static int
+static bool
bitset_stats_disjoint_p (bitset dst, bitset src)
{
BITSET_CHECK2_ (dst, src);
}
-static int
+static bool
bitset_stats_equal_p (bitset dst, bitset src)
{
BITSET_CHECK2_ (dst, src);
}
-static int
+static bool
bitset_stats_subset_p (bitset dst, bitset src)
{
BITSET_CHECK2_ (dst, src);
}
-static int
+static bool
bitset_stats_and_cmp (bitset dst, bitset src1, bitset src2)
{
BITSET_CHECK3_ (dst, src1, src2);
}
-static int
+static bool
bitset_stats_andn_cmp (bitset dst, bitset src1, bitset src2)
{
BITSET_CHECK3_ (dst, src1, src2);
}
-static int
+static bool
bitset_stats_or_cmp (bitset dst, bitset src1, bitset src2)
{
BITSET_CHECK3_ (dst, src1, src2);
}
-static int
+static bool
bitset_stats_xor_cmp (bitset dst, bitset src1, bitset src2)
{
BITSET_CHECK3_ (dst, src1, src2);
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);
}
-static int
+static bool
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);
}
-static int
+static bool
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);
}
-static int
+static bool
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_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)
{
case BITSET_ARRAY:
bytes = abitset_bytes (n_bits);
- sbset = (bitset) xcalloc (1, bytes);
+ sbset = xcalloc (1, bytes);
abitset_init (sbset, n_bits);
break;
case BITSET_LIST:
bytes = lbitset_bytes (n_bits);
- sbset = (bitset) xcalloc (1, bytes);
+ sbset = xcalloc (1, bytes);
lbitset_init (sbset, n_bits);
break;
case BITSET_TABLE:
bytes = ebitset_bytes (n_bits);
- sbset = (bitset) xcalloc (1, bytes);
+ sbset = xcalloc (1, bytes);
ebitset_init (sbset, n_bits);
break;
+ case BITSET_VARRAY:
+ bytes = vbitset_bytes (n_bits);
+ sbset = xcalloc (1, bytes);
+ vbitset_init (sbset, n_bits);
+ break;
+
default:
abort ();
}