* bitset: expose bitset_resize
@ 2019-03-19 8:23 Akim Demaille
2019-03-19 11:53 ` Bruno Haible
0 siblings, 1 reply; 4+ messages in thread
From: Akim Demaille @ 2019-03-19 8:23 UTC (permalink / raw)
To: Gnulib bugs
Ok to install?
commit 6c5d6f2d2479807d84837e0e9f93048be985e0f7
Author: Akim Demaille <akim.demaille@gmail.com>
Date: Mon Mar 18 18:27:27 2019 +0100
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.
diff --git a/ChangeLog b/ChangeLog
index 81e371048..858e0a3ba 100644
--- 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-17 Akim Demaille <akim@lrde.epita.fr>
_Noreturn: GCC 4.7 does not support [[noreturn]] in C++11 mode
diff --git a/lib/bitset.h b/lib/bitset.h
index 32d08e7aa..ecd02148f 100644
--- a/lib/bitset.h
+++ b/lib/bitset.h
@@ -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)
diff --git a/tests/test-bitset.c b/tests/test-bitset.c
index cef910d53..282ccef4a 100644
--- a/tests/test-bitset.c
+++ b/tests/test-bitset.c
@@ -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;
}
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: bitset: expose bitset_resize
2019-03-19 8:23 bitset: expose bitset_resize Akim Demaille
@ 2019-03-19 11:53 ` Bruno Haible
2019-03-19 12:20 ` Akim Demaille
0 siblings, 1 reply; 4+ messages in thread
From: Bruno Haible @ 2019-03-19 11:53 UTC (permalink / raw)
To: bug-gnulib; +Cc: Akim Demaille
Hi Akim,
> Ok to install?
Just a comment:
> + ARRAY bitsets cannot be resized. */
This comment should better be added to bitset.h. Users will not look into the
test's source code in order to learn about limitations of the API.
Bruno
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: bitset: expose bitset_resize
2019-03-19 11:53 ` Bruno Haible
@ 2019-03-19 12:20 ` Akim Demaille
2019-03-21 6:20 ` Akim Demaille
0 siblings, 1 reply; 4+ messages in thread
From: Akim Demaille @ 2019-03-19 12:20 UTC (permalink / raw)
To: Bruno Haible; +Cc: bug-gnulib
> Le 19 mars 2019 à 12:53, Bruno Haible <bruno@clisp.org> a écrit :
>
> Hi Akim,
>
>> Ok to install?
>
> Just a comment:
>
>> + ARRAY bitsets cannot be resized. */
>
> This comment should better be added to bitset.h. Users will not look into the
> test's source code in order to learn about limitations of the API.
This is already documented. It's not a limitation, it's a specification of one of the available implementations :)
> @item BITSET_ARRAY
> Array of bits (fixed size, fast for dense bitsets). Memory for bit array
> and bitset structure allocated contiguously.
I just meant the test to be easier to understand for the casual user.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: bitset: expose bitset_resize
2019-03-19 12:20 ` Akim Demaille
@ 2019-03-21 6:20 ` Akim Demaille
0 siblings, 0 replies; 4+ messages in thread
From: Akim Demaille @ 2019-03-21 6:20 UTC (permalink / raw)
To: Bruno Haible; +Cc: bug-gnulib
> Le 19 mars 2019 à 13:20, Akim Demaille <akim@lrde.epita.fr> a écrit :
>
>> Le 19 mars 2019 à 12:53, Bruno Haible <bruno@clisp.org> a écrit :
>>
>> Hi Akim,
>>
>>> Ok to install?
Installed.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2019-03-21 6:20 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-19 8:23 bitset: expose bitset_resize Akim Demaille
2019-03-19 11:53 ` Bruno Haible
2019-03-19 12:20 ` Akim Demaille
2019-03-21 6:20 ` Akim Demaille
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).