public inbox for gsl-discuss@sourceware.org
 help / color / mirror / Atom feed
* RFC bit_vectors
@ 2008-05-21  9:13 Alxneit-Kamber Ivo
  2008-05-22  8:02 ` Brian Gough
  0 siblings, 1 reply; 3+ messages in thread
From: Alxneit-Kamber Ivo @ 2008-05-21  9:13 UTC (permalink / raw)
  To: gsl-discuss


[-- Attachment #1.1: Type: text/plain, Size: 1736 bytes --]

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

[-- Attachment #1.2: bit_vector.tar.gz --]
[-- Type: application/x-compressed-tar, Size: 5962 bytes --]

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: RFC bit_vectors
  2008-05-21  9:13 RFC bit_vectors Alxneit-Kamber Ivo
@ 2008-05-22  8:02 ` Brian Gough
  2008-05-22 11:34   ` Ivo Alxneit
  0 siblings, 1 reply; 3+ messages in thread
From: Brian Gough @ 2008-05-22  8:02 UTC (permalink / raw)
  To: Alxneit-Kamber Ivo; +Cc: gsl-discuss

At Wed, 21 May 2008 11:13:14 +0200,
Alxneit-Kamber Ivo wrote:
> 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.

Hello,

Did you have a specific use in mind?  This is probably more suited to
a general C library rather than scientific library.  

-- 
Brian Gough

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: RFC bit_vectors
  2008-05-22  8:02 ` Brian Gough
@ 2008-05-22 11:34   ` Ivo Alxneit
  0 siblings, 0 replies; 3+ messages in thread
From: Ivo Alxneit @ 2008-05-22 11:34 UTC (permalink / raw)
  To: Brian Gough; +Cc: gsl-discuss

[-- Attachment #1: Type: text/plain, Size: 2080 bytes --]


On Thu, 2008-05-22 at 09:01 +0100, Brian Gough wrote:
> At Wed, 21 May 2008 11:13:14 +0200,
> Alxneit-Kamber Ivo wrote:
> > 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.
> 
> Hello,
> 
> Did you have a specific use in mind?  This is probably more suited to
> a general C library rather than scientific library.  
> 

well, i used bit_vectors "to keep track of information". i had a global
gsl_vector, some of its elements shared among different (only a few)
objects. because each object would access "most" of the elemets of the
gsl_vector it was much cheeper to use one bit_vector per object to keep
track of the information needed than to use one gsl_vector per object.
the gsl_vector was dynamically growing and became very large (~1GB). so
i ended up with code like 

res=0.0;
for(i=0; i< n; i++)
  res += gsl_vector_get(v,i)*bit_vector_test(bv,i);

to only sum the contribution of object bv.

the read/write/print was used mainly for debugging. some of the logical
operators were used in situations to find elements shared by a group of
objects or unique to a certain object. shift was implemented just for
fun.

bit_vector are probaly not suited to do math of very large integers
(like 2048 bit numbers).

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


[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2008-05-22 11:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-05-21  9:13 RFC bit_vectors Alxneit-Kamber Ivo
2008-05-22  8:02 ` Brian Gough
2008-05-22 11:34   ` Ivo Alxneit

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).