summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog9
-rw-r--r--lib/bitset/stats.c8
-rw-r--r--tests/test-bitset.c4
3 files changed, 20 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 6775744036..64be77149e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
2020-11-19 Akim Demaille <akim@lrde.epita.fr>
+ bitset: tests: exercise the stats too
+
+ * tests/test-bitset.c: Display the stats at the end of the test.
+ * lib/bitset/stats.c (bitset_log_histogram_print): When diplaying the
+ last bin, display "256-..." rather that "256-511", since the last bin
+ does count item greater than or equal to 256.
+
+2020-11-19 Akim Demaille <akim@lrde.epita.fr>
+
bitset: tests: try harder to break it
* tests/test-bitset.c (compare): Be ready to use bitsets larger than
BITSET_LIST_SIZE.
diff --git a/lib/bitset/stats.c b/lib/bitset/stats.c
index 5bd44c06a4..df9264285f 100644
--- a/lib/bitset/stats.c
+++ b/lib/bitset/stats.c
@@ -154,13 +154,19 @@ bitset_log_histogram_print (FILE *file, const char *name, const char *msg,
fprintf (file, "%*d\t%8u (%5.1f%%)\n",
max_width, i, bins[i], 100.0 * bins[i] / total);
- for (; i < n_bins; i++)
+ for (; i < n_bins - 1; i++)
fprintf (file, "%*lu-%lu\t%8u (%5.1f%%)\n",
max_width - ((unsigned) (0.30103 * (i) + 0.9999) + 1),
1UL << (i - 1),
(1UL << i) - 1,
bins[i],
(100.0 * bins[i]) / total);
+
+ fprintf (file, "%*lu-...\t%8u (%5.1f%%)\n",
+ max_width - ((unsigned) (0.30103 * (i) + 0.9999) + 1),
+ 1UL << (i - 1),
+ bins[i],
+ (100.0 * bins[i]) / total);
}
}
diff --git a/tests/test-bitset.c b/tests/test-bitset.c
index 9a2d7c5216..6fa656a227 100644
--- a/tests/test-bitset.c
+++ b/tests/test-bitset.c
@@ -358,6 +358,8 @@ check_attributes (enum bitset_attr attr, int nbits)
int main (void)
{
+ bitset_stats_enable ();
+
for (int i = 0; i < 4; ++i)
{
/* table bitsets have elements that store 256 bits. bitset_list
@@ -382,5 +384,7 @@ int main (void)
compare (BITSET_VARIABLE, BITSET_SPARSE);
compare (BITSET_VARIABLE, BITSET_FRUGAL);
compare (BITSET_VARIABLE, BITSET_GREEDY);
+
+ bitset_stats_dump (stderr);
return 0;
}