BitArray implementation issue

H. S. Teoh via Digitalmars-d digitalmars-d at puremagic.com
Tue Jul 22 18:03:33 PDT 2014


On Tue, Jul 22, 2014 at 05:57:48PM -0700, H. S. Teoh via Digitalmars-d wrote:
[....]
> You might want to consider implementing a way of tracking how many
> bits in the final word are valid. That way, you can correctly trigger
> reallocation if the user tries to write to a bit beyond the current
> end of the array (instead of stomping over other BitArray's data), and
> you don't have to clear any bits except newly-allocated words.
> Assuming we want to keep dynamic-array-like behaviour for BitArray,
> that is. I think it's a good idea.

Hmm. It looks like the code is already counting bits rather than words.
So you should already have enough information to implement the correct
solution (take the current length modulo the number of bits per word,
and that tells you which bits in the last word are valid).


T

-- 
Let's not fight disease by killing the patient. -- Sean 'Shaleh' Perry


More information about the Digitalmars-d mailing list