RFC bit_vectors
Alxneit-Kamber Ivo
ivo.alxneit@psi.ch
Wed May 21 09:13:00 GMT 2008
Hi everybody,
attached please find an implementation of 'bit_vectors' (maybe bit
fields would be a better name) that might be an interesting addition to
GSL. 'bit_vectors' can be used similarly like a C bit field, only that
they grow and shrink dynamically depending on the number of bits in use.
Currently the user is limited to 'maximum(size_t)' bits (the bit number
is passed as size_t) or by the amount of memory available. Note,
however, that memory for all bits does not necessarily need to be
allocated because high bits that are either all 1 or 0 are stored as a
single implied bit.
I have implemented the following
basic functions: init / free / set bit / clear bit / test bit
utility functions: copy / print / fread / fwrite
bit wise logical operators: and / or / xor / not
shift operator: generic / left shift / right shift
'test.c' illustrates the use of bit_vectors. It is not intended to be a
strict verification er test of the code.
I am aware that one of the design criteria of GSL, using a preallocated
workspace instead of performing deep-allocations, is (deliberately)
violated. I thinks that this makes sense here. bit_vectors are, per
definition, infinitely long (within practical limits) and are intended
for situations where the user has no a-priory knowledge of how many
bits will be needed. Under normal circumstances (a few thousands bits
needed) allocation should never fail.
Comments, critisism wellcome.
regards
--
Dr. Ivo Alxneit
Laboratory for Solar Technology phone: +41 56 310 4092
Paul Scherrer Institute fax: +41 56 310 2688
CH-5232 Villigen http://solar.web.psi.ch
Switzerland gnupg key: 0x515E30C7
-------------- next part --------------
A non-text attachment was scrubbed...
Name: bit_vector.tar.gz
Type: application/x-compressed-tar
Size: 5962 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/gsl-discuss/attachments/20080521/fa79de00/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: <http://sourceware.org/pipermail/gsl-discuss/attachments/20080521/fa79de00/attachment.sig>
More information about the Gsl-discuss
mailing list