www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Phobos degrades: ndslice vs (BitArray + Bitwise)

reply Ilya Yaroshenko <ilyayaroshenko gmail.com> writes:
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]);
}
Dec 07 2016
parent reply jmh530 <john.michael.hall gmail.com> writes:
On Wednesday, 7 December 2016 at 11:39:06 UTC, Ilya Yaroshenko 
wrote:
 Phobos is degrades.
I think I understand what you mean here, but there's definitely a translation issue.
Dec 07 2016
parent Ilya Yaroshenko <ilyayaroshenko gmail.com> writes:
On Wednesday, 7 December 2016 at 15:11:36 UTC, jmh530 wrote:
 On Wednesday, 7 December 2016 at 11:39:06 UTC, Ilya Yaroshenko 
 wrote:
 Phobos is degrades.
I think I understand what you mean here, but there's definitely a translation issue.
Yes, my bad. In Russian it has not so big negative shade like in English. Andrei proposed a good solution for the Bitwise problem. --Ilya
Dec 07 2016