const version for foreach/opApply

Matthias Walter xammy at xammy.homelinux.net
Sun Jun 10 23:04:47 PDT 2012


On 06/10/2012 12:30 AM, Era Scarecrow wrote:
> On Saturday, 9 June 2012 at 10:09:25 UTC, Matthias Walter wrote:
>> First, thank you for your answer. I've already made some tiny
>> modifications in order to make BitArray work for my purposes:
>>
>> https://github.com/xammy/phobos/commit/eb46d99217f2bf1e6d173964e2954248b08146d6
>>
>>
>> If you plan to create pull requests for your changes - please consider
>> my changes as well. When do you expect to finish, I.e., create a pull
>> request for phobos?
> 
>  Curious... Almost all of the changes you proposed I've already added in
> my version, the toHash is the only one missing and I don't know if I can
> work that very well. The new version is going to include 'slice-like'
> features, which is mostly a couple extra numbers specifying the offset
> in bits from the beginning to the end; The problem with that is hashing
> would have a huge speed drop.
> 
>  I'm adding an 'realign' function that handles those cases, but the
> downside is shared slices where you would want to make changes may or
> may not work. Caching the result would also be useful... Hmmm...
> 
>  I don't suppose you have a toHash where I can enter the odd bits and
> then also bulk ones and have the hash return the same could you? I can

I see the problem. I don't know whether my hash function is a good one -
I just needed it to make AAs work with BitArray as a key type.

But the question is interesting. Finding a good hash function for bit
arrays which is invariant under realignment.

> see xor easily having this type of effect...
> 
>  Anyways, here's some things I can do so far; Got a few improvements
> left to do, but not many. (const & immutable friendly of course :) )
> 
> -- 
> 
> const BitArray ba = BitArray([1,1,0,0,1]);
> const BitArray slice = ba[1 .. ba.length];
> BitArray m = slice.dup;
> immutable BitArray im = slice.idup;
> 
> assert(slice == ba[1 .. ba.length]);
> assert(slice == [1,0,0,1]);
> assert(slice == m);
> assert(slice == im);
> 
> assert(slice.isCompact);
> writeln("GC not used");
> 

Looks interesting!




More information about the Digitalmars-d-learn mailing list