bitset_stats.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728
  1. /* Bitset statistics.
  2. Copyright (C) 2002-2006, 2009-2013 Free Software Foundation, Inc.
  3. Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz).
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  14. /* This file is a wrapper bitset implementation for the other bitset
  15. implementations. It provides bitset compatibility checking and
  16. statistics gathering without having to instrument the bitset
  17. implementations. When statistics gathering is enabled, the bitset
  18. operations get vectored through here and we then call the appropriate
  19. routines. */
  20. #include <config.h>
  21. #include "bitset_stats.h"
  22. #include "bbitset.h"
  23. #include "abitset.h"
  24. #include "ebitset.h"
  25. #include "lbitset.h"
  26. #include "vbitset.h"
  27. #include <stdlib.h>
  28. #include <string.h>
  29. #include <stdio.h>
  30. #include "gettext.h"
  31. #define _(Msgid) gettext (Msgid)
  32. /* Configuration macros. */
  33. #define BITSET_STATS_FILE "bitset.dat"
  34. #define BITSET_LOG_COUNT_BINS 10
  35. #define BITSET_LOG_SIZE_BINS 16
  36. #define BITSET_DENSITY_BINS 20
  37. /* Accessor macros. */
  38. #define BITSET_STATS_ALLOCS_INC(TYPE) \
  39. bitset_stats_info->types[(TYPE)].allocs++
  40. #define BITSET_STATS_FREES_INC(BSET) \
  41. bitset_stats_info->types[BITSET_TYPE_ (BSET)].frees++
  42. #define BITSET_STATS_SETS_INC(BSET) \
  43. bitset_stats_info->types[BITSET_TYPE_ (BSET)].sets++
  44. #define BITSET_STATS_CACHE_SETS_INC(BSET) \
  45. bitset_stats_info->types[BITSET_TYPE_ (BSET)].cache_sets++
  46. #define BITSET_STATS_RESETS_INC(BSET) \
  47. bitset_stats_info->types[BITSET_TYPE_ (BSET)].resets++
  48. #define BITSET_STATS_CACHE_RESETS_INC(BSET) \
  49. bitset_stats_info->types[BITSET_TYPE_ (BSET)].cache_resets++
  50. #define BITSET_STATS_TESTS_INC(BSET) \
  51. bitset_stats_info->types[BITSET_TYPE_ (BSET)].tests++
  52. #define BITSET_STATS_CACHE_TESTS_INC(BSET) \
  53. bitset_stats_info->types[BITSET_TYPE_ (BSET)].cache_tests++
  54. #define BITSET_STATS_LISTS_INC(BSET) \
  55. bitset_stats_info->types[BITSET_TYPE_ (BSET)].lists++
  56. #define BITSET_STATS_LIST_COUNTS_INC(BSET, I) \
  57. bitset_stats_info->types[BITSET_TYPE_ (BSET)].list_counts[(I)]++
  58. #define BITSET_STATS_LIST_SIZES_INC(BSET, I) \
  59. bitset_stats_info->types[BITSET_TYPE_ (BSET)].list_sizes[(I)]++
  60. #define BITSET_STATS_LIST_DENSITY_INC(BSET, I) \
  61. bitset_stats_info->types[BITSET_TYPE_ (BSET)].list_density[(I)]++
  62. struct bitset_type_info_struct
  63. {
  64. unsigned int allocs;
  65. unsigned int frees;
  66. unsigned int lists;
  67. unsigned int sets;
  68. unsigned int cache_sets;
  69. unsigned int resets;
  70. unsigned int cache_resets;
  71. unsigned int tests;
  72. unsigned int cache_tests;
  73. unsigned int list_counts[BITSET_LOG_COUNT_BINS];
  74. unsigned int list_sizes[BITSET_LOG_SIZE_BINS];
  75. unsigned int list_density[BITSET_DENSITY_BINS];
  76. };
  77. struct bitset_stats_info_struct
  78. {
  79. unsigned int runs;
  80. struct bitset_type_info_struct types[BITSET_TYPE_NUM];
  81. };
  82. struct bitset_stats_info_struct bitset_stats_info_data;
  83. struct bitset_stats_info_struct *bitset_stats_info;
  84. bool bitset_stats_enabled = false;
  85. /* Print a percentage histogram with message MSG to FILE. */
  86. static void
  87. bitset_percent_histogram_print (FILE *file, const char *name, const char *msg,
  88. unsigned int n_bins, unsigned int *bins)
  89. {
  90. unsigned int i;
  91. unsigned int total;
  92. total = 0;
  93. for (i = 0; i < n_bins; i++)
  94. total += bins[i];
  95. if (!total)
  96. return;
  97. fprintf (file, "%s %s", name, msg);
  98. for (i = 0; i < n_bins; i++)
  99. fprintf (file, "%.0f-%.0f%%\t%8u (%5.1f%%)\n",
  100. i * 100.0 / n_bins,
  101. (i + 1) * 100.0 / n_bins, bins[i],
  102. (100.0 * bins[i]) / total);
  103. }
  104. /* Print a log histogram with message MSG to FILE. */
  105. static void
  106. bitset_log_histogram_print (FILE *file, const char *name, const char *msg,
  107. unsigned int n_bins, unsigned int *bins)
  108. {
  109. unsigned int i;
  110. unsigned int total;
  111. unsigned int max_width;
  112. total = 0;
  113. for (i = 0; i < n_bins; i++)
  114. total += bins[i];
  115. if (!total)
  116. return;
  117. /* Determine number of useful bins. */
  118. for (i = n_bins; i > 3 && ! bins[i - 1]; i--)
  119. continue;
  120. n_bins = i;
  121. /* 2 * ceil (log10 (2) * (N - 1)) + 1. */
  122. max_width = 2 * (unsigned int) (0.30103 * (n_bins - 1) + 0.9999) + 1;
  123. fprintf (file, "%s %s", name, msg);
  124. for (i = 0; i < 2; i++)
  125. fprintf (file, "%*d\t%8u (%5.1f%%)\n",
  126. max_width, i, bins[i], 100.0 * bins[i] / total);
  127. for (; i < n_bins; i++)
  128. fprintf (file, "%*lu-%lu\t%8u (%5.1f%%)\n",
  129. max_width - ((unsigned int) (0.30103 * (i) + 0.9999) + 1),
  130. 1UL << (i - 1),
  131. (1UL << i) - 1,
  132. bins[i],
  133. (100.0 * bins[i]) / total);
  134. }
  135. /* Print bitset statistics to FILE. */
  136. static void
  137. bitset_stats_print_1 (FILE *file, const char *name,
  138. struct bitset_type_info_struct *stats)
  139. {
  140. if (!stats)
  141. return;
  142. fprintf (file, "%s:\n", name);
  143. fprintf (file, _("%u bitset_allocs, %u freed (%.2f%%).\n"),
  144. stats->allocs, stats->frees,
  145. stats->allocs ? 100.0 * stats->frees / stats->allocs : 0);
  146. fprintf (file, _("%u bitset_sets, %u cached (%.2f%%)\n"),
  147. stats->sets, stats->cache_sets,
  148. stats->sets ? 100.0 * stats->cache_sets / stats->sets : 0);
  149. fprintf (file, _("%u bitset_resets, %u cached (%.2f%%)\n"),
  150. stats->resets, stats->cache_resets,
  151. stats->resets ? 100.0 * stats->cache_resets / stats->resets : 0);
  152. fprintf (file, _("%u bitset_tests, %u cached (%.2f%%)\n"),
  153. stats->tests, stats->cache_tests,
  154. stats->tests ? 100.0 * stats->cache_tests / stats->tests : 0);
  155. fprintf (file, _("%u bitset_lists\n"), stats->lists);
  156. bitset_log_histogram_print (file, name, _("count log histogram\n"),
  157. BITSET_LOG_COUNT_BINS, stats->list_counts);
  158. bitset_log_histogram_print (file, name, _("size log histogram\n"),
  159. BITSET_LOG_SIZE_BINS, stats->list_sizes);
  160. bitset_percent_histogram_print (file, name, _("density histogram\n"),
  161. BITSET_DENSITY_BINS, stats->list_density);
  162. }
  163. /* Print all bitset statistics to FILE. */
  164. static void
  165. bitset_stats_print (FILE *file, bool verbose ATTRIBUTE_UNUSED)
  166. {
  167. int i;
  168. if (!bitset_stats_info)
  169. return;
  170. fprintf (file, _("Bitset statistics:\n\n"));
  171. if (bitset_stats_info->runs > 1)
  172. fprintf (file, _("Accumulated runs = %u\n"), bitset_stats_info->runs);
  173. for (i = 0; i < BITSET_TYPE_NUM; i++)
  174. bitset_stats_print_1 (file, bitset_type_names[i],
  175. &bitset_stats_info->types[i]);
  176. }
  177. /* Initialise bitset statistics logging. */
  178. void
  179. bitset_stats_enable (void)
  180. {
  181. if (!bitset_stats_info)
  182. bitset_stats_info = &bitset_stats_info_data;
  183. bitset_stats_enabled = true;
  184. }
  185. void
  186. bitset_stats_disable (void)
  187. {
  188. bitset_stats_enabled = false;
  189. }
  190. /* Read bitset statistics file. */
  191. void
  192. bitset_stats_read (const char *file_name)
  193. {
  194. FILE *file;
  195. if (!bitset_stats_info)
  196. return;
  197. if (!file_name)
  198. file_name = BITSET_STATS_FILE;
  199. file = fopen (file_name, "r");
  200. if (file)
  201. {
  202. if (fread (&bitset_stats_info_data, sizeof (bitset_stats_info_data),
  203. 1, file) != 1)
  204. {
  205. if (ferror (file))
  206. perror (_("cannot read stats file"));
  207. else
  208. fprintf (stderr, _("bad stats file size\n"));
  209. }
  210. if (fclose (file) != 0)
  211. perror (_("cannot read stats file"));
  212. }
  213. bitset_stats_info_data.runs++;
  214. }
  215. /* Write bitset statistics file. */
  216. void
  217. bitset_stats_write (const char *file_name)
  218. {
  219. FILE *file;
  220. if (!bitset_stats_info)
  221. return;
  222. if (!file_name)
  223. file_name = BITSET_STATS_FILE;
  224. file = fopen (file_name, "w");
  225. if (file)
  226. {
  227. if (fwrite (&bitset_stats_info_data, sizeof (bitset_stats_info_data),
  228. 1, file) != 1)
  229. perror (_("cannot write stats file"));
  230. if (fclose (file) != 0)
  231. perror (_("cannot write stats file"));
  232. }
  233. else
  234. perror (_("cannot open stats file for writing"));
  235. }
  236. /* Dump bitset statistics to FILE. */
  237. void
  238. bitset_stats_dump (FILE *file)
  239. {
  240. bitset_stats_print (file, false);
  241. }
  242. /* Function to be called from debugger to print bitset stats. */
  243. void
  244. debug_bitset_stats (void)
  245. {
  246. bitset_stats_print (stderr, true);
  247. }
  248. static void
  249. bitset_stats_set (bitset dst, bitset_bindex bitno)
  250. {
  251. bitset bset = dst->s.bset;
  252. bitset_windex wordno = bitno / BITSET_WORD_BITS;
  253. bitset_windex offset = wordno - bset->b.cindex;
  254. BITSET_STATS_SETS_INC (bset);
  255. if (offset < bset->b.csize)
  256. {
  257. bset->b.cdata[offset] |= (bitset_word) 1 << (bitno % BITSET_WORD_BITS);
  258. BITSET_STATS_CACHE_SETS_INC (bset);
  259. }
  260. else
  261. BITSET_SET_ (bset, bitno);
  262. }
  263. static void
  264. bitset_stats_reset (bitset dst, bitset_bindex bitno)
  265. {
  266. bitset bset = dst->s.bset;
  267. bitset_windex wordno = bitno / BITSET_WORD_BITS;
  268. bitset_windex offset = wordno - bset->b.cindex;
  269. BITSET_STATS_RESETS_INC (bset);
  270. if (offset < bset->b.csize)
  271. {
  272. bset->b.cdata[offset] &=
  273. ~((bitset_word) 1 << (bitno % BITSET_WORD_BITS));
  274. BITSET_STATS_CACHE_RESETS_INC (bset);
  275. }
  276. else
  277. BITSET_RESET_ (bset, bitno);
  278. }
  279. static bool
  280. bitset_stats_toggle (bitset src, bitset_bindex bitno)
  281. {
  282. return BITSET_TOGGLE_ (src->s.bset, bitno);
  283. }
  284. static bool
  285. bitset_stats_test (bitset src, bitset_bindex bitno)
  286. {
  287. bitset bset = src->s.bset;
  288. bitset_windex wordno = bitno / BITSET_WORD_BITS;
  289. bitset_windex offset = wordno - bset->b.cindex;
  290. BITSET_STATS_TESTS_INC (bset);
  291. if (offset < bset->b.csize)
  292. {
  293. BITSET_STATS_CACHE_TESTS_INC (bset);
  294. return (bset->b.cdata[offset] >> (bitno % BITSET_WORD_BITS)) & 1;
  295. }
  296. else
  297. return BITSET_TEST_ (bset, bitno);
  298. }
  299. static bitset_bindex
  300. bitset_stats_resize (bitset src, bitset_bindex size)
  301. {
  302. return BITSET_RESIZE_ (src->s.bset, size);
  303. }
  304. static bitset_bindex
  305. bitset_stats_size (bitset src)
  306. {
  307. return BITSET_SIZE_ (src->s.bset);
  308. }
  309. static bitset_bindex
  310. bitset_stats_count (bitset src)
  311. {
  312. return BITSET_COUNT_ (src->s.bset);
  313. }
  314. static bool
  315. bitset_stats_empty_p (bitset dst)
  316. {
  317. return BITSET_EMPTY_P_ (dst->s.bset);
  318. }
  319. static void
  320. bitset_stats_ones (bitset dst)
  321. {
  322. BITSET_ONES_ (dst->s.bset);
  323. }
  324. static void
  325. bitset_stats_zero (bitset dst)
  326. {
  327. BITSET_ZERO_ (dst->s.bset);
  328. }
  329. static void
  330. bitset_stats_copy (bitset dst, bitset src)
  331. {
  332. BITSET_CHECK2_ (dst, src);
  333. BITSET_COPY_ (dst->s.bset, src->s.bset);
  334. }
  335. static bool
  336. bitset_stats_disjoint_p (bitset dst, bitset src)
  337. {
  338. BITSET_CHECK2_ (dst, src);
  339. return BITSET_DISJOINT_P_ (dst->s.bset, src->s.bset);
  340. }
  341. static bool
  342. bitset_stats_equal_p (bitset dst, bitset src)
  343. {
  344. BITSET_CHECK2_ (dst, src);
  345. return BITSET_EQUAL_P_ (dst->s.bset, src->s.bset);
  346. }
  347. static void
  348. bitset_stats_not (bitset dst, bitset src)
  349. {
  350. BITSET_CHECK2_ (dst, src);
  351. BITSET_NOT_ (dst->s.bset, src->s.bset);
  352. }
  353. static bool
  354. bitset_stats_subset_p (bitset dst, bitset src)
  355. {
  356. BITSET_CHECK2_ (dst, src);
  357. return BITSET_SUBSET_P_ (dst->s.bset, src->s.bset);
  358. }
  359. static void
  360. bitset_stats_and (bitset dst, bitset src1, bitset src2)
  361. {
  362. BITSET_CHECK3_ (dst, src1, src2);
  363. BITSET_AND_ (dst->s.bset, src1->s.bset, src2->s.bset);
  364. }
  365. static bool
  366. bitset_stats_and_cmp (bitset dst, bitset src1, bitset src2)
  367. {
  368. BITSET_CHECK3_ (dst, src1, src2);
  369. return BITSET_AND_CMP_ (dst->s.bset, src1->s.bset, src2->s.bset);
  370. }
  371. static void
  372. bitset_stats_andn (bitset dst, bitset src1, bitset src2)
  373. {
  374. BITSET_CHECK3_ (dst, src1, src2);
  375. BITSET_ANDN_ (dst->s.bset, src1->s.bset, src2->s.bset);
  376. }
  377. static bool
  378. bitset_stats_andn_cmp (bitset dst, bitset src1, bitset src2)
  379. {
  380. BITSET_CHECK3_ (dst, src1, src2);
  381. return BITSET_ANDN_CMP_ (dst->s.bset, src1->s.bset, src2->s.bset);
  382. }
  383. static void
  384. bitset_stats_or (bitset dst, bitset src1, bitset src2)
  385. {
  386. BITSET_CHECK3_ (dst, src1, src2);
  387. BITSET_OR_ (dst->s.bset, src1->s.bset, src2->s.bset);
  388. }
  389. static bool
  390. bitset_stats_or_cmp (bitset dst, bitset src1, bitset src2)
  391. {
  392. BITSET_CHECK3_ (dst, src1, src2);
  393. return BITSET_OR_CMP_ (dst->s.bset, src1->s.bset, src2->s.bset);
  394. }
  395. static void
  396. bitset_stats_xor (bitset dst, bitset src1, bitset src2)
  397. {
  398. BITSET_CHECK3_ (dst, src1, src2);
  399. BITSET_XOR_ (dst->s.bset, src1->s.bset, src2->s.bset);
  400. }
  401. static bool
  402. bitset_stats_xor_cmp (bitset dst, bitset src1, bitset src2)
  403. {
  404. BITSET_CHECK3_ (dst, src1, src2);
  405. return BITSET_XOR_CMP_ (dst->s.bset, src1->s.bset, src2->s.bset);
  406. }
  407. static void
  408. bitset_stats_and_or (bitset dst, bitset src1, bitset src2, bitset src3)
  409. {
  410. BITSET_CHECK4_ (dst, src1, src2, src3);
  411. BITSET_AND_OR_ (dst->s.bset, src1->s.bset, src2->s.bset, src3->s.bset);
  412. }
  413. static bool
  414. bitset_stats_and_or_cmp (bitset dst, bitset src1, bitset src2, bitset src3)
  415. {
  416. BITSET_CHECK4_ (dst, src1, src2, src3);
  417. return BITSET_AND_OR_CMP_ (dst->s.bset, src1->s.bset, src2->s.bset, src3->s.bset);
  418. }
  419. static void
  420. bitset_stats_andn_or (bitset dst, bitset src1, bitset src2, bitset src3)
  421. {
  422. BITSET_CHECK4_ (dst, src1, src2, src3);
  423. BITSET_ANDN_OR_ (dst->s.bset, src1->s.bset, src2->s.bset, src3->s.bset);
  424. }
  425. static bool
  426. bitset_stats_andn_or_cmp (bitset dst, bitset src1, bitset src2, bitset src3)
  427. {
  428. BITSET_CHECK4_ (dst, src1, src2, src3);
  429. return BITSET_ANDN_OR_CMP_ (dst->s.bset, src1->s.bset, src2->s.bset, src3->s.bset);
  430. }
  431. static void
  432. bitset_stats_or_and (bitset dst, bitset src1, bitset src2, bitset src3)
  433. {
  434. BITSET_CHECK4_ (dst, src1, src2, src3);
  435. BITSET_OR_AND_ (dst->s.bset, src1->s.bset, src2->s.bset, src3->s.bset);
  436. }
  437. static bool
  438. bitset_stats_or_and_cmp (bitset dst, bitset src1, bitset src2, bitset src3)
  439. {
  440. BITSET_CHECK4_ (dst, src1, src2, src3);
  441. return BITSET_OR_AND_CMP_ (dst->s.bset, src1->s.bset, src2->s.bset, src3->s.bset);
  442. }
  443. static bitset_bindex
  444. bitset_stats_list (bitset bset, bitset_bindex *list,
  445. bitset_bindex num, bitset_bindex *next)
  446. {
  447. bitset_bindex count;
  448. bitset_bindex tmp;
  449. bitset_bindex size;
  450. bitset_bindex i;
  451. count = BITSET_LIST_ (bset->s.bset, list, num, next);
  452. BITSET_STATS_LISTS_INC (bset->s.bset);
  453. /* Log histogram of number of set bits. */
  454. for (i = 0, tmp = count; tmp; tmp >>= 1, i++)
  455. continue;
  456. if (i >= BITSET_LOG_COUNT_BINS)
  457. i = BITSET_LOG_COUNT_BINS - 1;
  458. BITSET_STATS_LIST_COUNTS_INC (bset->s.bset, i);
  459. /* Log histogram of number of bits in set. */
  460. size = BITSET_SIZE_ (bset->s.bset);
  461. for (i = 0, tmp = size; tmp; tmp >>= 1, i++)
  462. continue;
  463. if (i >= BITSET_LOG_SIZE_BINS)
  464. i = BITSET_LOG_SIZE_BINS - 1;
  465. BITSET_STATS_LIST_SIZES_INC (bset->s.bset, i);
  466. /* Histogram of fraction of bits set. */
  467. i = size ? (count * BITSET_DENSITY_BINS) / size : 0;
  468. if (i >= BITSET_DENSITY_BINS)
  469. i = BITSET_DENSITY_BINS - 1;
  470. BITSET_STATS_LIST_DENSITY_INC (bset->s.bset, i);
  471. return count;
  472. }
  473. static bitset_bindex
  474. bitset_stats_list_reverse (bitset bset, bitset_bindex *list,
  475. bitset_bindex num, bitset_bindex *next)
  476. {
  477. return BITSET_LIST_REVERSE_ (bset->s.bset, list, num, next);
  478. }
  479. static void
  480. bitset_stats_free (bitset bset)
  481. {
  482. BITSET_STATS_FREES_INC (bset->s.bset);
  483. BITSET_FREE_ (bset->s.bset);
  484. }
  485. struct bitset_vtable bitset_stats_vtable = {
  486. bitset_stats_set,
  487. bitset_stats_reset,
  488. bitset_stats_toggle,
  489. bitset_stats_test,
  490. bitset_stats_resize,
  491. bitset_stats_size,
  492. bitset_stats_count,
  493. bitset_stats_empty_p,
  494. bitset_stats_ones,
  495. bitset_stats_zero,
  496. bitset_stats_copy,
  497. bitset_stats_disjoint_p,
  498. bitset_stats_equal_p,
  499. bitset_stats_not,
  500. bitset_stats_subset_p,
  501. bitset_stats_and,
  502. bitset_stats_and_cmp,
  503. bitset_stats_andn,
  504. bitset_stats_andn_cmp,
  505. bitset_stats_or,
  506. bitset_stats_or_cmp,
  507. bitset_stats_xor,
  508. bitset_stats_xor_cmp,
  509. bitset_stats_and_or,
  510. bitset_stats_and_or_cmp,
  511. bitset_stats_andn_or,
  512. bitset_stats_andn_or_cmp,
  513. bitset_stats_or_and,
  514. bitset_stats_or_and_cmp,
  515. bitset_stats_list,
  516. bitset_stats_list_reverse,
  517. bitset_stats_free,
  518. BITSET_STATS
  519. };
  520. /* Return enclosed bitset type. */
  521. enum bitset_type
  522. bitset_stats_type_get (bitset bset)
  523. {
  524. return BITSET_TYPE_ (bset->s.bset);
  525. }
  526. size_t
  527. bitset_stats_bytes (void)
  528. {
  529. return sizeof (struct bitset_stats_struct);
  530. }
  531. bitset
  532. bitset_stats_init (bitset bset, bitset_bindex n_bits, enum bitset_type type)
  533. {
  534. size_t bytes;
  535. bitset sbset;
  536. bset->b.vtable = &bitset_stats_vtable;
  537. /* Disable cache. */
  538. bset->b.cindex = 0;
  539. bset->b.csize = 0;
  540. bset->b.cdata = 0;
  541. BITSET_NBITS_ (bset) = n_bits;
  542. /* Set up the actual bitset implementation that
  543. we are a wrapper over. */
  544. switch (type)
  545. {
  546. default:
  547. abort ();
  548. case BITSET_ARRAY:
  549. bytes = abitset_bytes (n_bits);
  550. sbset = xcalloc (1, bytes);
  551. abitset_init (sbset, n_bits);
  552. break;
  553. case BITSET_LIST:
  554. bytes = lbitset_bytes (n_bits);
  555. sbset = xcalloc (1, bytes);
  556. lbitset_init (sbset, n_bits);
  557. break;
  558. case BITSET_TABLE:
  559. bytes = ebitset_bytes (n_bits);
  560. sbset = xcalloc (1, bytes);
  561. ebitset_init (sbset, n_bits);
  562. break;
  563. case BITSET_VARRAY:
  564. bytes = vbitset_bytes (n_bits);
  565. sbset = xcalloc (1, bytes);
  566. vbitset_init (sbset, n_bits);
  567. break;
  568. }
  569. bset->s.bset = sbset;
  570. BITSET_STATS_ALLOCS_INC (type);
  571. return bset;
  572. }