Creates a BitArray from a bool array, such that bool values read from left to right correspond to subsequent bits in the BitArray.
Creates a BitArray from the raw contents of the source array. The source array is not copied but simply acts as the underlying array of bits, which stores data as size_t units.
Counts all the set bits in the BitArray
Flips all the bits in the BitArray
Flips a single bit, specified by pos
Support for foreach loops for BitArray.
Support for binary bitwise operators for BitArray.
Support for binary operator ~ for BitArray.
Convert to void[].
Convert to size_t[].
Supports comparison operators for BitArray.
Support for operators == and != for BitArray.
Gets the i'th bit in the BitArray.
Sets the i'th bit in the BitArray.
Support for operator op= for BitArray.
Support for operator ~= for BitArray. Warning: This will overwrite a bit in the final word of the current underlying data regardless of whether it is shared between BitArray objects. i.e. D dynamic array concatenation semantics are not followed
Operator <<= support.
Operator >>= support.
Sets all the values in the BitArray to the value specified by val.
Sets the bits of a slice of BitArray starting at index start and ends at index ($D end - 1) with the values specified by val.
Support for unary operator ~ for BitArray.
Support for hashing for BitArray.
Return a string representation of this BitArray.
Return a lazy range of the indices of set bits.
Duplicates the BitArray and its contents.
Sets the amount of bits in the BitArray. Warning: increasing length may overwrite bits in the final word of the current underlying data regardless of whether it is shared between BitArray objects. i.e. D dynamic array extension semantics are not followed.
Reverses the bits of the BitArray.
Sorts the BitArray's elements.
Slicing & bitsSet
import std.algorithm.comparison : equal; import std.range : iota; bool[] buf = new bool[64 * 3]; buf[0 .. 64] = true; BitArray b = BitArray(buf); assert(b.bitsSet.equal(iota(0, 64))); b <<= 64; assert(b.bitsSet.equal(iota(64, 128)));
Concatenation and appending
import std.algorithm.comparison : equal; auto b = BitArray([1, 0]); b ~= true; assert(b[2] == 1); b ~= BitArray([0, 1]); auto c = BitArray([1, 0, 1, 0, 1]); assert(b == c); assert(b.bitsSet.equal([0, 2, 4]));
Bit flipping
import std.algorithm.comparison : equal; auto b = BitArray([1, 1, 0, 1]); b &= BitArray([0, 1, 1, 0]); assert(b.bitsSet.equal([1])); b.flip; assert(b.bitsSet.equal([0, 2, 3]));
String format of bitarrays
import std.format : format; auto b = BitArray([1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1]); assert(format("%b", b) == "1_00001111_00001111");
import std.format : format; BitArray b; b = BitArray([]); assert(format("%s", b) == "[]"); assert(format("%b", b) is null); b = BitArray([1]); assert(format("%s", b) == "[1]"); assert(format("%b", b) == "1"); b = BitArray([0, 0, 0, 0]); assert(format("%b", b) == "0000"); b = BitArray([0, 0, 0, 0, 1, 1, 1, 1]); assert(format("%s", b) == "[0, 0, 0, 0, 1, 1, 1, 1]"); assert(format("%b", b) == "00001111"); b = BitArray([0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1]); assert(format("%s", b) == "[0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1]"); assert(format("%b", b) == "00001111_00001111"); b = BitArray([1, 0, 0, 0, 0, 1, 1, 1, 1]); assert(format("%b", b) == "1_00001111"); b = BitArray([1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1]); assert(format("%b", b) == "1_00001111_00001111");
A dynamic array of bits. Each bit in a BitArray can be manipulated individually or by the standard bitwise operators &, |, ^, ~, >>, << and also by other effective member functions; most of them work relative to the BitArray's dimension (see dim), instead of its length.