Phobos degrades: ndslice vs (BitArray + Bitwise)

Ilya Yaroshenko via Digitalmars-d digitalmars-d at puremagic.com
Wed Dec 7 03:39:06 PST 2016


Phobos is degrades. There is a good example:

1. We have BitArray in std.bitmanip:
  http://dlang.org/phobos/std_bitmanip.html#.BitArray

2. We are going to add Bitwise, 300+ LOC in std.range
  https://github.com/dlang/phobos/pull/4927

The code below represents ndslice implementation.

The benefits are:

1. It is faster then Bitwise.
2. It has (all) range primitives comparing with BitArray.
3. Its implementation is very simple.
4. multidimensional analog out of the box
5. All ndslice iterators and selectors are available.

We are adding new and new API, more and more code and 
specializations into Phobos. This is bad direction. Small number 
of basic universal concepts it much more better then soup 
consisting of "everything you may need".

--------------

import core.bitop;
import std.experimental.ndslice;

struct BitMap
{
     size_t* ptr;

     bool opIndex(size_t index) const
     {
         return bt(ptr, index) != 0;
     }

     void opIndexAssign(bool val, size_t index)
     {
         if(val)
             bts(ptr, index);
         else
             btr(ptr, index);
     }
}

void main()
{
     auto arr = new size_t[3];
     auto sl = BitMap(arr.ptr).sliced(size_t.sizeof * 8 * 
arr.length);

     sl[4] = true;
     sl[100] = true;
     sl.popFrontN(3); // La-la-la
     assert(sl[1]);
     assert(sl[97]);
}



More information about the Digitalmars-d mailing list