Fix Issue 20241 - BitArray.bitsSet ignores length

This commit is contained in:
Vladimir Panteleev 2019-09-25 07:50:24 +00:00
parent 01fd74a699
commit 289149a2f1
No known key found for this signature in database
GPG key ID: 5004F0FAD051576D

View file

@ -2585,12 +2585,16 @@ public:
@property auto bitsSet() const nothrow
{
import std.algorithm.iteration : filter, map, joiner;
import std.range : iota;
import std.range : iota, chain;
return iota(dim).
filter!(i => _ptr[i])().
map!(i => BitsSet!size_t(_ptr[i], i * bitsPerSizeT))().
joiner();
return chain(
iota(fullWords)
.filter!(i => _ptr[i])()
.map!(i => BitsSet!size_t(_ptr[i], i * bitsPerSizeT))()
.joiner(),
iota(fullWords * bitsPerSizeT, _len)
.filter!(i => this[i])()
);
}
///
@ -2630,6 +2634,16 @@ public:
assert(b.bitsSet.equal(iota(wordBits * 2)));
}
// Issue 20241
@system unittest
{
BitArray ba;
ba.length = 2;
ba[1] = 1;
ba.length = 1;
assert(ba.bitsSet.empty);
}
private void formatBitString(Writer)(auto ref Writer sink) const
{
if (!length)