BitArray/BitFields - Review

Dmitry Olshansky dmitry.olsh at gmail.com
Sun Jul 29 03:34:49 PDT 2012


On 29-Jul-12 14:28, Era Scarecrow wrote:
> On Sunday, 29 July 2012 at 09:30:06 UTC, Dmitry Olshansky wrote:
>>
>> I have simpler suggestion. Maybe doing it as 2 containers:
>>
>> BitSet is a plain value type with small array optimization (what you
>> called BitArray in last 2 posts) and no slicing (only as opSlice()
>> I.e. as a whole). Best used for small things under < 1000 bits (as
>> even dup will be cheap enough).
>>
>> BitArray is class or struct that has reference smenatics and drops
>> small array optimization in favor of having simple & fast slicing Best
>> used for big arrays with no less then 100-200 bits.
>
>   As long as you only use one or the other then it sounds great; I'm
> sure a conversion/constructor would be available to convert from one to
> another. That does seem like the best solution, but also feels like
> we're building it twice (Little code re-use).
>

Yup.

>   Might be a third option: A template struct that represents a BitArray
> type (with 90% of the code); you then insert a structure with key
> functions that would handle the value/reference & duplication part.
>

Sounds a lot like mixin template. I'd try to invent some small set of 
primitive operations and auto-magically construct the others from it.

>   I'll meditate on it for a few days and see if anything pops up.

And just to keep your mind busy :) how about adding SIMD to speed it all up:
http://dlang.org/simd.html
It's kind of new & cool thing but not very well documented.

-- 
Dmitry Olshansky


More information about the Digitalmars-d-learn mailing list