Issue 10650 - std.bitmanip.FixedBitArray
Summary: std.bitmanip.FixedBitArray
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P4 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-07-15 17:00 UTC by bearophile_hugs
Modified: 2024-12-01 16:18 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description bearophile_hugs 2013-07-15 17:00:54 UTC
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.
Comment 1 dlangBugzillaToGithub 2024-12-01 16:18:17 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/phobos/issues/9610

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB