makeReallocatedBitArrayZeroPadded

@safe @system
size_t*
makeReallocatedBitArrayZeroPadded
(
alias Allocator
)
(
size_t* input
,
const size_t currentBitCount
,
const size_t newBitCount
)
if (
__traits(hasMember, Allocator, "reallocate")
)

Return Value

Type: size_t*

input reallocated to contain newBitCount number of bits. New bits are default-initialized to zero.

Examples

enum bitCount = 8*size_t.sizeof + 1;

size_t* x = makeUninitializedBitArray!(Allocator)(bitCount);
Allocator.instance.deallocate(cast(void[])(x[0 .. wordCountOfBitCount(bitCount)]));
size_t bitCount = 1;
size_t* y = makeBitArrayZeroed!(Allocator)(bitCount).ptr; // start empty
while (bitCount < 100_000) {
	const newBitCount = bitCount * 2;
	y = makeReallocatedBitArrayZeroPadded!(Allocator)(y, bitCount, newBitCount);
	bitCount = newBitCount;

	// check contents
	foreach (immutable bitIndex; 0 .. bitCount)
		assert(bt(y, bitIndex) == 0);
}
Allocator.instance.deallocate(cast(void[]) (y[0 .. wordCountOfBitCount(bitCount)]));

Meta