]> Savannah Git Hosting - gnulib.git/commitdiff
bitset: expose bitset_resize
authorAkim Demaille <akim.demaille@gmail.com>
Mon, 18 Mar 2019 17:27:27 +0000 (18:27 +0100)
committerAkim Demaille <akim.demaille@gmail.com>
Thu, 21 Mar 2019 06:18:17 +0000 (07:18 +0100)
* lib/bitset.h (bitset_resize): Bounce on the polymorphic implementation.
* tests/test-bitset.c (check_attributes): Check bitset_resize.
(main): Use a variable bitset as reference, since fixed does not support resize.

ChangeLog
lib/bitset.h
tests/test-bitset.c

index 977414f0846882d8974aed5193726999650c8494..714610027a6b8bb05791084b1e9c605eb806df6c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2019-03-19  Akim Demaille  <akim@lrde.epita.fr>
+
+       bitset: expose bitset_resize
+       * lib/bitset.h (bitset_resize): Bounce on the polymorphic implementation.
+       * tests/test-bitset.c (check_attributes): Check bitset_resize.
+       (main): Use a variable bitset as reference, since fixed does not support resize.
+
 2019-03-19  Bruno Haible  <bruno@clisp.org>
 
        doc: Document the 'stdnoreturn' and 'noreturn' modules.
index 32d08e7aa97adfaa959305afb0090faaeecaac21..ecd02148f0fd4bc7d4f09950a73bc8c5f5e8053c 100644 (file)
@@ -178,8 +178,9 @@ bitset_test (bitset bset, bitset_bindex bitno)
 /* Return size in bits of bitset SRC.  */
 #define bitset_size(SRC) BITSET_SIZE_ (SRC)
 
-/* Change size of bitset.  */
-void bitset_resize (bitset, bitset_bindex);
+/* Change size in bits of bitset.  New bits are zeroed.  Return
+   SIZE.  */
+#define bitset_resize(DST, SIZE) BITSET_RESIZE_ (DST, SIZE)
 
 /* Return number of bits set in bitset SRC.  */
 #define bitset_count(SRC) BITSET_COUNT_ (SRC)
index cef910d53a5b98ca1111f2a07ada98364ded8c0f..282ccef4a65eb5dfe92a728f3ff789b47d789400 100644 (file)
@@ -139,6 +139,19 @@ void compare (enum bitset_attr a, enum bitset_attr b)
   bitset_zero (bdst);
   assert_bitset_equal (adst, bdst);
 
+  /* resize.
+
+     ARRAY bitsets cannot be resized.  */
+  if (bitset_type_get (bsrc0) != BITSET_ARRAY)
+    {
+      const int nbits_new = RANDOM (256);
+      bitset_copy (adst, asrc0);
+      bitset_copy (bdst, bsrc0);
+      ASSERT (nbits_new == bitset_resize (adst, nbits_new));
+      ASSERT (nbits_new == bitset_resize (bdst, nbits_new));
+      assert_bitset_equal (adst, bdst);
+    }
+
   bitset_free (bdst);
   bitset_free (bsrc3);
   bitset_free (bsrc2);
@@ -204,11 +217,11 @@ int main (void)
   check_attributes (BITSET_FRUGAL);
   check_attributes (BITSET_GREEDY);
 
-  compare (BITSET_FIXED, BITSET_FIXED);
-  compare (BITSET_FIXED, BITSET_VARIABLE);
-  compare (BITSET_FIXED, BITSET_DENSE);
-  compare (BITSET_FIXED, BITSET_SPARSE);
-  compare (BITSET_FIXED, BITSET_FRUGAL);
-  compare (BITSET_FIXED, BITSET_GREEDY);
+  compare (BITSET_VARIABLE, BITSET_FIXED);
+  compare (BITSET_VARIABLE, BITSET_VARIABLE);
+  compare (BITSET_VARIABLE, BITSET_DENSE);
+  compare (BITSET_VARIABLE, BITSET_SPARSE);
+  compare (BITSET_VARIABLE, BITSET_FRUGAL);
+  compare (BITSET_VARIABLE, BITSET_GREEDY);
   return 0;
 }