Re: boolean sequence
Tone =A6koda wrote:
> in C++ if you have an array of 100 boolean (0 or 1) values it will take
> only 100 bits (the C++ "bitset" class exists), in euphoria same array
> will take 32*100bits, 32x more memory. so if you have very large array,
> there is big difference between 1 MB and 32 MB. 1 MB will quickly
> allocate, 32 MB will take long to allocate.
>
> does in euphoria exist any such library? similar library could exist
> for array with char types (8bit) (0-255 numbers), and array with short
> types (16bit) (0 to 65,535 numbers).
>
> i want such library to save memory and also maybe speed.
In the Euphoria archieves, there is my library "bit.zip".
Besides other routines, it contains 5 functions that let you
treat 32-bit integers as "bit arrays". Short descriptions:
- x = bit_set(x, number)
Set the bit in 'x', that is indexed by 'number', to 1.
- x = bit_reset(x, number)
Set the bit in 'x', that is indexed by 'number', to 0.
- i = bit_test(x, number)
Return the value (0 or 1) of the bit in 'x', that is
indexed by 'number'.
- i = bit_scan_forward(x)
Return the number of the lowest order bit in 'x', that is
set (or return -1, if x = 0).
- i = bit_scan_reverse(x)
Return the number of the highest order bit in 'x', that is
set (or return -1, if x = 0).
All these functions are fast, because they are internally
implemented in ASM.
Regards,
Juergen
--=20
A: Because it considerably reduces the readability of the text.
Q: Why?
A: Top posting.
Q: What is annoying in e-mail and news?
|
Not Categorized, Please Help
|
|