www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 10650] New: std.bitmanip.FixedBitArray

http://d.puremagic.com/issues/show_bug.cgi?id=10650

           Summary: std.bitmanip.FixedBitArray
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc



This is a struct with no defined constructor that uses a bit array of
statically known size:


import std.bitmanip: BitArray;
struct Foo {
    enum nBits = 1_024;
    size_t[nBits / size_t.sizeof] buffer;
    BitArray bitSet;
    bool isInitialized = false;

    void bar() /*pure nothrow*/ {
        if (!isInitialized) {
             bitSet.init(buffer, nBits);
             isInitialized = true;
         }

        // .......
    }
}
void main() {}



A statically known size is useful to reduce pressure a bit on the GC, to
increase cache locality, etc. So I suggest to introduce in std.bitmanip a
simple FixedBitArray based on BitArray that offers a simpler usage for
statically known sizes of bit arrays:


struct FixedBitArray(size_t nBits) {
    private size_t[nBits / size_t.sizeof + (nBits % size_t.sizeof) ? 1 : 0]
buffer;
...
}


import std.bitmanip: FixedBitArray;
struct Foo {
    FixedBitArray!(1_024) bitSet;

    void bar() pure nothrow {
        // .......
    }
}
void main() {}


An alternative name is "BoundedBitArray" as in the Ada 2012 bounded
collections.

An alternative is to modify BitArray to allow both usages nicely.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 15 2013