]> git.saurik.com Git - bison.git/blame - lib/bitset_stats.c
(ebitset_bytes): Use size_t, not unsigned int, to count bytes.
[bison.git] / lib / bitset_stats.c
CommitLineData
613f5e1a
AD
1/* Bitset statistics.
2 Copyright (C) 2002 Free Software Foundation, Inc.
3 Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz).
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18*/
19
20/* This file is a wrapper bitset implementation for the other bitset
21 implementations. It provides bitset compatibility checking and
22 statistics gathering without having to instrument the bitset
23 implementations. When statistics gathering is enabled, the bitset
24 operations get vectored through here and we then call the appropriate
25 routines.
26*/
27
28#ifdef HAVE_CONFIG_H
29#include "config.h"
30#endif
31
32#include "bbitset.h"
33#include "abitset.h"
34#include "ebitset.h"
35#include "lbitset.h"
36#include "bitset_stats.h"
37#include <stdlib.h>
38#include <string.h>
39#include <stdio.h>
40
c131cbff
PE
41#include "gettext.h"
42#define _(Msgid) gettext (Msgid)
613f5e1a
AD
43
44/* Configuration macros. */
45#define BITSET_STATS_FILE "bitset.dat"
46#define BITSET_LOG_COUNT_BINS 10
47#define BITSET_LOG_SIZE_BINS 16
48#define BITSET_DENSITY_BINS 20
49
50
51/* Accessor macros. */
52#define BITSET_STATS_ALLOCS_INC(TYPE) \
53 bitset_stats_info->types[(TYPE)].allocs++
54#define BITSET_STATS_FREES_INC(BSET) \
55 bitset_stats_info->types[BITSET_TYPE_ (BSET)].frees++
56#define BITSET_STATS_SETS_INC(BSET) \
57 bitset_stats_info->types[BITSET_TYPE_ (BSET)].sets++
58#define BITSET_STATS_CACHE_SETS_INC(BSET) \
59 bitset_stats_info->types[BITSET_TYPE_ (BSET)].cache_sets++
60#define BITSET_STATS_RESETS_INC(BSET) \
61 bitset_stats_info->types[BITSET_TYPE_ (BSET)].resets++
62#define BITSET_STATS_CACHE_RESETS_INC(BSET) \
63 bitset_stats_info->types[BITSET_TYPE_ (BSET)].cache_resets++
64#define BITSET_STATS_TESTS_INC(BSET) \
65 bitset_stats_info->types[BITSET_TYPE_ (BSET)].tests++
66#define BITSET_STATS_CACHE_TESTS_INC(BSET) \
67 bitset_stats_info->types[BITSET_TYPE_ (BSET)].cache_tests++
68#define BITSET_STATS_LISTS_INC(BSET) \
69 bitset_stats_info->types[BITSET_TYPE_ (BSET)].lists++
70#define BITSET_STATS_LIST_COUNTS_INC(BSET, I) \
71 bitset_stats_info->types[BITSET_TYPE_ (BSET)].list_counts[(I)]++
72#define BITSET_STATS_LIST_SIZES_INC(BSET, I) \
73 bitset_stats_info->types[BITSET_TYPE_ (BSET)].list_sizes[(I)]++
74#define BITSET_STATS_LIST_DENSITY_INC(BSET, I) \
75 bitset_stats_info->types[BITSET_TYPE_ (BSET)].list_density[(I)]++
76
77
78typedef struct bitset_stats_struct
79{
80 bitset bset;
81} *bitset_stats;
82
83
84struct bitset_struct
85{
86 struct bbitset_struct b;
87 struct bitset_stats_struct s;
88};
89
90
91struct bitset_type_info_struct
92{
93 unsigned int allocs;
94 unsigned int frees;
95 unsigned int lists;
96 unsigned int sets;
97 unsigned int cache_sets;
98 unsigned int resets;
99 unsigned int cache_resets;
100 unsigned int tests;
101 unsigned int cache_tests;
102 unsigned int list_counts[BITSET_LOG_COUNT_BINS];
103 unsigned int list_sizes[BITSET_LOG_SIZE_BINS];
104 unsigned int list_density[BITSET_DENSITY_BINS];
105};
106
107struct bitset_stats_info_struct
108{
109 unsigned int runs;
110 struct bitset_type_info_struct types[BITSET_TYPE_NUM];
111};
112
113
114struct bitset_stats_info_struct bitset_stats_info_data;
115struct bitset_stats_info_struct *bitset_stats_info;
116int bitset_stats_enabled = 0;
117
118
119static void bitset_stats_set PARAMS ((bitset, bitset_bindex));
120static void bitset_stats_reset PARAMS ((bitset, bitset_bindex));
6aa452a6 121static int bitset_stats_toggle PARAMS ((bitset, bitset_bindex));
613f5e1a 122static int bitset_stats_test PARAMS ((bitset, bitset_bindex));
2d382ea8
PE
123static bitset_bindex bitset_stats_size PARAMS ((bitset));
124static bitset_bindex bitset_stats_list PARAMS ((bitset, bitset_bindex *,
125 bitset_bindex,
126 bitset_bindex *));
127static bitset_bindex bitset_stats_list_reverse
613f5e1a
AD
128PARAMS ((bitset, bitset_bindex *, bitset_bindex, bitset_bindex *));
129static void bitset_stats_free PARAMS ((bitset));
130static void bitset_percent_histogram_print PARAMS ((FILE *, const char *,
131 const char *,
132 unsigned int,
133 unsigned int *));
134static void bitset_log_histogram_print PARAMS ((FILE *, const char *,
135 const char *,
136 unsigned int,
137 unsigned int *));
138static void bitset_stats_print_1
139PARAMS ((FILE *, const char *, struct bitset_type_info_struct *));
140static void bitset_stats_print PARAMS ((FILE *, int));
141
142
143/* Print a percentage histogram with message MSG to FILE. */
144static void
145bitset_percent_histogram_print (file, name, msg, n_bins, bins)
146 FILE *file;
147 const char *name;
148 const char *msg;
149 unsigned int n_bins;
150 unsigned int *bins;
151{
152 unsigned int i;
153 unsigned int total;
154
155 total = 0;
156 for (i = 0; i < n_bins; i++)
157 total += bins[i];
158
159 if (!total)
160 return;
161
162 fprintf (file, "%s %s", name, msg);
163 for (i = 0; i < n_bins; i++)
2d382ea8 164 fprintf (file, "%.0f-%.0f%%\t%8u (%5.1f%%)\n",
613f5e1a
AD
165 i * 100.0 / n_bins,
166 (i + 1) * 100.0 / n_bins, bins[i],
167 (100.0 * bins[i]) / total);
168}
169
170
171/* Print a log histogram with message MSG to FILE. */
172static void
173bitset_log_histogram_print (file, name, msg, n_bins, bins)
174 FILE *file;
175 const char *name;
176 const char *msg;
177 unsigned int n_bins;
178 unsigned int *bins;
179{
180 unsigned int i;
181 unsigned int total;
182 unsigned int max_width;
613f5e1a
AD
183
184 total = 0;
185 for (i = 0; i < n_bins; i++)
186 total += bins[i];
187
188 if (!total)
189 return;
190
6aa452a6 191 /* Determine number of useful bins. */
613f5e1a
AD
192 for (i = n_bins; i > 3 && ! bins[i - 1]; i--)
193 continue;
6aa452a6 194 n_bins = i;
613f5e1a
AD
195
196 /* 2 * ceil (log10 (2) * (N - 1)) + 1. */
197 max_width = 2 * (unsigned int) (0.30103 * (n_bins - 1) + 0.9999) + 1;
198
199 fprintf (file, "%s %s", name, msg);
200 for (i = 0; i < 2; i++)
2d382ea8 201 fprintf (file, "%*d\t%8u (%5.1f%%)\n",
613f5e1a
AD
202 max_width, i, bins[i], 100.0 * bins[i] / total);
203
6aa452a6 204 for (; i < n_bins; i++)
2d382ea8 205 fprintf (file, "%*lu-%lu\t%8u (%5.1f%%)\n",
613f5e1a 206 max_width - ((unsigned int) (0.30103 * (i) + 0.9999) + 1),
2d382ea8
PE
207 (unsigned long) 1 << (i - 1),
208 ((unsigned long) 1 << i) - 1,
209 bins[i],
613f5e1a
AD
210 (100.0 * bins[i]) / total);
211}
212
213
214/* Print bitset statistics to FILE. */
215static void
216bitset_stats_print_1 (file, name, stats)
217 FILE *file;
218 const char *name;
219 struct bitset_type_info_struct *stats;
220{
221 if (!stats)
222 return;
223
224 fprintf (file, "%s:\n", name);
2d382ea8 225 fprintf (file, _("%u bitset_allocs, %u freed (%.2f%%).\n"),
613f5e1a
AD
226 stats->allocs, stats->frees,
227 stats->allocs ? 100.0 * stats->frees / stats->allocs : 0);
2d382ea8 228 fprintf (file, _("%u bitset_sets, %u cached (%.2f%%)\n"),
613f5e1a
AD
229 stats->sets, stats->cache_sets,
230 stats->sets ? 100.0 * stats->cache_sets / stats->sets : 0);
2d382ea8 231 fprintf (file, _("%u bitset_resets, %u cached (%.2f%%)\n"),
613f5e1a
AD
232 stats->resets, stats->cache_resets,
233 stats->resets ? 100.0 * stats->cache_resets / stats->resets : 0);
2d382ea8 234 fprintf (file, _("%u bitset_tests, %u cached (%.2f%%)\n"),
613f5e1a
AD
235 stats->tests, stats->cache_tests,
236 stats->tests ? 100.0 * stats->cache_tests / stats->tests : 0);
237
2d382ea8 238 fprintf (file, _("%u bitset_lists\n"), stats->lists);
613f5e1a 239
c131cbff 240 bitset_log_histogram_print (file, name, _("count log histogram\n"),
613f5e1a
AD
241 BITSET_LOG_COUNT_BINS, stats->list_counts);
242
c131cbff 243 bitset_log_histogram_print (file, name, _("size log histogram\n"),
613f5e1a
AD
244 BITSET_LOG_SIZE_BINS, stats->list_sizes);
245
c131cbff 246 bitset_percent_histogram_print (file, name, _("density histogram\n"),
613f5e1a
AD
247 BITSET_DENSITY_BINS, stats->list_density);
248}
249
250
251/* Print all bitset statistics to FILE. */
252static void
253bitset_stats_print (file, verbose)
254 FILE *file;
255 int verbose ATTRIBUTE_UNUSED;
256{
257 int i;
613f5e1a
AD
258
259 if (!bitset_stats_info)
260 return;
261
c131cbff 262 fprintf (file, _("Bitset statistics:\n\n"));
613f5e1a
AD
263
264 if (bitset_stats_info->runs > 1)
2d382ea8 265 fprintf (file, _("Accumulated runs = %u\n"), bitset_stats_info->runs);
613f5e1a
AD
266
267 for (i = 0; i < BITSET_TYPE_NUM; i++)
6aa452a6
AD
268 bitset_stats_print_1 (file, bitset_type_names[i],
269 &bitset_stats_info->types[i]);
613f5e1a
AD
270}
271
272
273/* Initialise bitset statistics logging. */
274void
275bitset_stats_enable ()
276{
277 if (!bitset_stats_info)
278 bitset_stats_info = &bitset_stats_info_data;
279 bitset_stats_enabled = 1;
280}
281
282
283void
284bitset_stats_disable ()
285{
286 bitset_stats_enabled = 0;
287}
288
289
290/* Read bitset statistics file. */
291void
292bitset_stats_read (filename)
293 const char *filename;
294{
295 FILE *file;
296
297 if (!bitset_stats_info)
298 return;
299
300 if (!filename)
301 filename = BITSET_STATS_FILE;
302
303 file = fopen (filename, "r");
304 if (file)
305 {
306 if (fread (&bitset_stats_info_data, sizeof (bitset_stats_info_data),
307 1, file) != 1)
308 {
309 if (ferror (file))
c131cbff 310 perror (_("Could not read stats file."));
613f5e1a 311 else
c131cbff 312 fprintf (stderr, _("Bad stats file size.\n"));
613f5e1a
AD
313 }
314 fclose (file);
315 }
316 bitset_stats_info_data.runs++;
317}
318
319
320/* Write bitset statistics file. */
321void
322bitset_stats_write (filename)
323 const char *filename;
324{
325 FILE *file;
326
327 if (!bitset_stats_info)
328 return;
329
330 if (!filename)
331 filename = BITSET_STATS_FILE;
332
333 file = fopen (filename, "w");
334 if (file)
335 {
336 if (fwrite (&bitset_stats_info_data, sizeof (bitset_stats_info_data),
337 1, file) != 1)
c131cbff 338 perror (_("Could not write stats file."));
613f5e1a
AD
339 fclose (file);
340 }
341 else
c131cbff 342 perror (_("Could not open stats file for writing."));
613f5e1a
AD
343}
344
345
346/* Dump bitset statistics to FILE. */
347void
348bitset_stats_dump (file)
349 FILE *file;
350{
351 bitset_stats_print (file, 0);
352}
353
354
355/* Function to be called from debugger to print bitset stats. */
356void
357debug_bitset_stats (void)
358{
359 bitset_stats_print (stderr, 1);
360}
361
362
363static void
364bitset_stats_set (dst, bitno)
365 bitset dst;
366 bitset_bindex bitno;
367{
368 bitset bset = dst->s.bset;
c131cbff
PE
369 bitset_windex wordno = bitno / BITSET_WORD_BITS;
370 bitset_windex offset = wordno - bset->b.cindex;
613f5e1a
AD
371
372 BITSET_STATS_SETS_INC (bset);
373
374 if (offset < bset->b.csize)
375 {
c131cbff 376 bset->b.cdata[offset] |= (bitset_word) 1 << (bitno % BITSET_WORD_BITS);
613f5e1a
AD
377 BITSET_STATS_CACHE_SETS_INC (bset);
378 }
379 else
380 BITSET_SET_ (bset, bitno);
381}
382
383
384static void
385bitset_stats_reset (dst, bitno)
386 bitset dst;
387 bitset_bindex bitno;
388{
389 bitset bset = dst->s.bset;
c131cbff
PE
390 bitset_windex wordno = bitno / BITSET_WORD_BITS;
391 bitset_windex offset = wordno - bset->b.cindex;
613f5e1a
AD
392
393 BITSET_STATS_RESETS_INC (bset);
394
395 if (offset < bset->b.csize)
396 {
c131cbff
PE
397 bset->b.cdata[offset] &=
398 ~((bitset_word) 1 << (bitno % BITSET_WORD_BITS));
613f5e1a
AD
399 BITSET_STATS_CACHE_RESETS_INC (bset);
400 }
401 else
402 BITSET_RESET_ (bset, bitno);
403}
404
405
6aa452a6
AD
406static int
407bitset_stats_toggle (src, bitno)
408 bitset src;
409 bitset_bindex bitno;
410{
411 return BITSET_TOGGLE_ (src->s.bset, bitno);
412}
413
414
613f5e1a
AD
415static int
416bitset_stats_test (src, bitno)
417 bitset src;
418 bitset_bindex bitno;
419{
420 bitset bset = src->s.bset;
c131cbff
PE
421 bitset_windex wordno = bitno / BITSET_WORD_BITS;
422 bitset_windex offset = wordno - bset->b.cindex;
613f5e1a
AD
423
424 BITSET_STATS_TESTS_INC (bset);
425
426 if (offset < bset->b.csize)
427 {
428 BITSET_STATS_CACHE_TESTS_INC (bset);
429 return (bset->b.cdata[offset] >> (bitno % BITSET_WORD_BITS)) & 1;
430 }
431 else
432 return BITSET_TEST_ (bset, bitno);
433}
434
435
2d382ea8 436static bitset_bindex
613f5e1a
AD
437bitset_stats_size (src)
438 bitset src;
439{
440 return BITSET_SIZE_ (src->s.bset);
441}
442
443
2d382ea8 444static bitset_bindex
6aa452a6
AD
445bitset_stats_count (src)
446 bitset src;
447{
448 return BITSET_COUNT_ (src->s.bset);
449}
450
451
452static int
453bitset_stats_empty_p (dst)
454 bitset dst;
455{
456 return BITSET_EMPTY_P_ (dst->s.bset);
457}
458
459
460static void
461bitset_stats_ones (dst)
462 bitset dst;
463{
464 BITSET_ONES_ (dst->s.bset);
465}
466
467
468static void
469bitset_stats_zero (dst)
470 bitset dst;
471{
472 BITSET_ZERO_ (dst->s.bset);
473}
474
475
476static void
477bitset_stats_copy (dst, src)
478 bitset dst;
479 bitset src;
480{
481 BITSET_CHECK2_ (dst, src);
482 BITSET_COPY_ (dst->s.bset, src->s.bset);
483}
484
485
486static int
487bitset_stats_disjoint_p (dst, src)
613f5e1a 488 bitset dst;
6aa452a6 489 bitset src;
613f5e1a 490{
6aa452a6
AD
491 BITSET_CHECK2_ (dst, src);
492 return BITSET_DISJOINT_P_ (dst->s.bset, src->s.bset);
613f5e1a
AD
493}
494
495
496static int
6aa452a6 497bitset_stats_equal_p (dst, src)
613f5e1a
AD
498 bitset dst;
499 bitset src;
613f5e1a
AD
500{
501 BITSET_CHECK2_ (dst, src);
6aa452a6
AD
502 return BITSET_EQUAL_P_ (dst->s.bset, src->s.bset);
503}
504
505
506static void
507bitset_stats_not (dst, src)
508 bitset dst;
509 bitset src;
510{
511 BITSET_CHECK2_ (dst, src);
512 BITSET_NOT_ (dst->s.bset, src->s.bset);
513}
514
515
516static int
517bitset_stats_subset_p (dst, src)
518 bitset dst;
519 bitset src;
520{
521 BITSET_CHECK2_ (dst, src);
522 return BITSET_SUBSET_P_ (dst->s.bset, src->s.bset);
523}
524
525
526static void
527bitset_stats_and (dst, src1, src2)
528 bitset dst;
529 bitset src1;
530 bitset src2;
531{
532 BITSET_CHECK3_ (dst, src1, src2);
533 BITSET_AND_ (dst->s.bset, src1->s.bset, src2->s.bset);
534}
535
536
537static int
538bitset_stats_and_cmp (dst, src1, src2)
539 bitset dst;
540 bitset src1;
541 bitset src2;
542{
543 BITSET_CHECK3_ (dst, src1, src2);
544 return BITSET_AND_CMP_ (dst->s.bset, src1->s.bset, src2->s.bset);
545}
546
547
548static void
549bitset_stats_andn (dst, src1, src2)
550 bitset dst;
551 bitset src1;
552 bitset src2;
553{
554 BITSET_CHECK3_ (dst, src1, src2);
555 BITSET_ANDN_ (dst->s.bset, src1->s.bset, src2->s.bset);
556}
557
558
559static int
560bitset_stats_andn_cmp (dst, src1, src2)
561 bitset dst;
562 bitset src1;
563 bitset src2;
564{
565 BITSET_CHECK3_ (dst, src1, src2);
566 return BITSET_ANDN_CMP_ (dst->s.bset, src1->s.bset, src2->s.bset);
567}
568
569
570static void
571bitset_stats_or (dst, src1, src2)
572 bitset dst;
573 bitset src1;
574 bitset src2;
575{
576 BITSET_CHECK3_ (dst, src1, src2);
577 BITSET_OR_ (dst->s.bset, src1->s.bset, src2->s.bset);
578}
579
580
581static int
582bitset_stats_or_cmp (dst, src1, src2)
583 bitset dst;
584 bitset src1;
585 bitset src2;
586{
587 BITSET_CHECK3_ (dst, src1, src2);
588 return BITSET_OR_CMP_ (dst->s.bset, src1->s.bset, src2->s.bset);
589}
590
591
592static void
593bitset_stats_xor (dst, src1, src2)
594 bitset dst;
595 bitset src1;
596 bitset src2;
597{
598 BITSET_CHECK3_ (dst, src1, src2);
599 BITSET_XOR_ (dst->s.bset, src1->s.bset, src2->s.bset);
613f5e1a
AD
600}
601
602
603static int
6aa452a6 604bitset_stats_xor_cmp (dst, src1, src2)
613f5e1a
AD
605 bitset dst;
606 bitset src1;
607 bitset src2;
613f5e1a
AD
608{
609 BITSET_CHECK3_ (dst, src1, src2);
6aa452a6
AD
610 return BITSET_XOR_CMP_ (dst->s.bset, src1->s.bset, src2->s.bset);
611}
612
613
614static void
615bitset_stats_and_or (dst, src1, src2, src3)
616 bitset dst;
617 bitset src1;
618 bitset src2;
619 bitset src3;
620{
621 BITSET_CHECK4_ (dst, src1, src2, src3);
622
623 BITSET_AND_OR_ (dst->s.bset, src1->s.bset, src2->s.bset, src3->s.bset);
613f5e1a
AD
624}
625
626
627static int
6aa452a6 628bitset_stats_and_or_cmp (dst, src1, src2, src3)
613f5e1a
AD
629 bitset dst;
630 bitset src1;
631 bitset src2;
632 bitset src3;
613f5e1a
AD
633{
634 BITSET_CHECK4_ (dst, src1, src2, src3);
635
6aa452a6
AD
636 return BITSET_AND_OR_CMP_ (dst->s.bset, src1->s.bset, src2->s.bset, src3->s.bset);
637}
638
639
640static void
641bitset_stats_andn_or (dst, src1, src2, src3)
642 bitset dst;
643 bitset src1;
644 bitset src2;
645 bitset src3;
646{
647 BITSET_CHECK4_ (dst, src1, src2, src3);
648
649 BITSET_ANDN_OR_ (dst->s.bset, src1->s.bset, src2->s.bset, src3->s.bset);
650}
651
652
653static int
654bitset_stats_andn_or_cmp (dst, src1, src2, src3)
655 bitset dst;
656 bitset src1;
657 bitset src2;
658 bitset src3;
659{
660 BITSET_CHECK4_ (dst, src1, src2, src3);
661
662 return BITSET_ANDN_OR_CMP_ (dst->s.bset, src1->s.bset, src2->s.bset, src3->s.bset);
663}
664
665
666static void
667bitset_stats_or_and (dst, src1, src2, src3)
668 bitset dst;
669 bitset src1;
670 bitset src2;
671 bitset src3;
672{
673 BITSET_CHECK4_ (dst, src1, src2, src3);
674
675 BITSET_OR_AND_ (dst->s.bset, src1->s.bset, src2->s.bset, src3->s.bset);
676}
677
678
679static int
680bitset_stats_or_and_cmp (dst, src1, src2, src3)
681 bitset dst;
682 bitset src1;
683 bitset src2;
684 bitset src3;
685{
686 BITSET_CHECK4_ (dst, src1, src2, src3);
613f5e1a 687
6aa452a6 688 return BITSET_OR_AND_CMP_ (dst->s.bset, src1->s.bset, src2->s.bset, src3->s.bset);
613f5e1a
AD
689}
690
691
2d382ea8 692static bitset_bindex
613f5e1a
AD
693bitset_stats_list (bset, list, num, next)
694 bitset bset;
695 bitset_bindex *list;
696 bitset_bindex num;
697 bitset_bindex *next;
698{
699 bitset_bindex count;
700 bitset_bindex tmp;
701 bitset_bindex size;
702 bitset_bindex i;
703 enum bitset_type type;
704
705 count = BITSET_LIST_ (bset->s.bset, list, num, next);
706
707 type = BITSET_TYPE_ (bset->s.bset);
708 BITSET_STATS_LISTS_INC (bset->s.bset);
709
710 /* Log histogram of number of set bits. */
711 for (i = 0, tmp = count; tmp; tmp >>= 1, i++)
712 continue;
713 if (i >= BITSET_LOG_COUNT_BINS)
714 i = BITSET_LOG_COUNT_BINS - 1;
715 BITSET_STATS_LIST_COUNTS_INC (bset->s.bset, i);
716
717 /* Log histogram of number of bits in set. */
718 size = BITSET_SIZE_ (bset->s.bset);
719 for (i = 0, tmp = size; tmp; tmp >>= 1, i++)
720 continue;
721 if (i >= BITSET_LOG_SIZE_BINS)
722 i = BITSET_LOG_SIZE_BINS - 1;
723 BITSET_STATS_LIST_SIZES_INC (bset->s.bset, i);
724
725 /* Histogram of fraction of bits set. */
726 i = size ? (count * BITSET_DENSITY_BINS) / size : 0;
727 if (i >= BITSET_DENSITY_BINS)
728 i = BITSET_DENSITY_BINS - 1;
729 BITSET_STATS_LIST_DENSITY_INC (bset->s.bset, i);
730 return count;
731}
732
733
2d382ea8 734static bitset_bindex
6aa452a6 735bitset_stats_list_reverse (bset, list, num, next)
613f5e1a
AD
736 bitset bset;
737 bitset_bindex *list;
738 bitset_bindex num;
739 bitset_bindex *next;
740{
6aa452a6 741 return BITSET_LIST_REVERSE_ (bset->s.bset, list, num, next);
613f5e1a
AD
742}
743
744
745static void
746bitset_stats_free (bset)
747 bitset bset;
748{
749 BITSET_STATS_FREES_INC (bset->s.bset);
750 BITSET_FREE_ (bset->s.bset);
751}
752
753
6aa452a6 754struct bitset_vtable bitset_stats_vtable = {
613f5e1a
AD
755 bitset_stats_set,
756 bitset_stats_reset,
6aa452a6 757 bitset_stats_toggle,
613f5e1a
AD
758 bitset_stats_test,
759 bitset_stats_size,
6aa452a6
AD
760 bitset_stats_count,
761 bitset_stats_empty_p,
762 bitset_stats_ones,
763 bitset_stats_zero,
764 bitset_stats_copy,
765 bitset_stats_disjoint_p,
766 bitset_stats_equal_p,
767 bitset_stats_not,
768 bitset_stats_subset_p,
769 bitset_stats_and,
770 bitset_stats_and_cmp,
771 bitset_stats_andn,
772 bitset_stats_andn_cmp,
773 bitset_stats_or,
774 bitset_stats_or_cmp,
775 bitset_stats_xor,
776 bitset_stats_xor_cmp,
777 bitset_stats_and_or,
778 bitset_stats_and_or_cmp,
779 bitset_stats_andn_or,
780 bitset_stats_andn_or_cmp,
781 bitset_stats_or_and,
782 bitset_stats_or_and_cmp,
613f5e1a 783 bitset_stats_list,
6aa452a6 784 bitset_stats_list_reverse,
613f5e1a
AD
785 bitset_stats_free,
786 BITSET_STATS
787};
788
789
790/* Return enclosed bitset type. */
791enum bitset_type
792bitset_stats_type_get (bset)
793 bitset bset;
794{
795 return BITSET_TYPE_ (bset->s.bset);
796}
797
798
2d382ea8
PE
799size_t
800bitset_stats_bytes (void)
613f5e1a
AD
801{
802 return sizeof (struct bitset_struct);
803}
804
805
806bitset
807bitset_stats_init (bset, n_bits, type)
808 bitset bset;
809 bitset_bindex n_bits;
810 enum bitset_type type;
811{
2d382ea8 812 size_t bytes;
613f5e1a
AD
813 bitset sbset;
814
6aa452a6 815 bset->b.vtable = &bitset_stats_vtable;
613f5e1a
AD
816
817 /* Disable cache. */
818 bset->b.cindex = 0;
819 bset->b.csize = 0;
820 bset->b.cdata = 0;
821
822 /* Set up the actual bitset implementation that
823 we are a wrapper over. */
824 switch (type)
825 {
826 case BITSET_ARRAY:
827 bytes = abitset_bytes (n_bits);
828 sbset = (bitset) xcalloc (1, bytes);
829 abitset_init (sbset, n_bits);
830 break;
831
832 case BITSET_LIST:
833 bytes = lbitset_bytes (n_bits);
834 sbset = (bitset) xcalloc (1, bytes);
835 lbitset_init (sbset, n_bits);
836 break;
837
838 case BITSET_TABLE:
839 bytes = ebitset_bytes (n_bits);
840 sbset = (bitset) xcalloc (1, bytes);
841 ebitset_init (sbset, n_bits);
842 break;
843
844 default:
845 abort ();
846 }
847
848 bset->s.bset = sbset;
849
850 BITSET_STATS_ALLOCS_INC (type);
851
852 return bset;
853}