On 30.05.2012 15:04, Era Scarecrow wrote:
[snip]

Other features: Slice operations available, so you can slice specific
sets of bits. Since opDollar doesn't work right I can't rely on them
just yet. uses and accepts ulong for the slices and opIndex. The
BitArray footprint is about 36 bytes for 32bit systems, and likely
40bytes for 64bit systems.

It all went nice and well...
Ouch why 36 bytes?


bool[4] x = [1, 1, 0, 0];
BitArray ba = BitArray(x);

ba = ba[2 .. ba.length]; //or BitArray(x, 2, x.length)
assert(ba == x[2 .. $]);


// const

ba = BitArray(x);
const BitArray cba = ba;
assert(cba == ba);

const BitArray slice = ba[2 .. ba.length]; //slices work too!
assert(ba[2 .. cba.length] == cba);
ba[0 .. 2] = cba[];


// compact / GC-less.

assert(ba.isCompact()); //if it's true, no GC involved.
BitArray ca = ba;
ca[0] = 0;
assert(ca != ba);

ba.length = 1000;
assert(!ba.isCompact()); //GC'd
ba = ba[0 .. 4];
assert(!ba.isCompact()); //slice doesn't automatically convert to compact

ca = ba;
ca[0] = 0;
assert(ba == ca); //like a regular slice, shares memory

Cool.

--
Dmitry Olshansky

Reply via email to