tango.core.BitArray

This module contains a packed bit array implementation in the style of D's built-in dynamic arrays.

License:
BSD style:

Authors:
Walter Bright, Sean Kelly

struct BitArray;
This struct represents an array of boolean values, each of which occupy one bit of memory for storage. Thus an array of 32 bits would occupy the same space as one integer value. The typical array operations--such as indexing and sorting--are supported, as well as bitwise operations such as and, or, xor, and complement.

pure this(size_t _len, size_t* _ptr);
This initializes a BitArray of bits.length bits, where each bit value matches the corresponding boolean value in bits.

Params:
bits The initialization value.

Returns:
A BitArray with the same number and sequence of elements as bits.

const const pure @property size_t length();
Get the number of bits in this array.

Returns:
The number of bits in this array.

pure @property void length(const size_t newlen);
Resizes this array to newlen bits. If newlen is larger than the current length, the new bits will be initialized to zero.

Params:
size_t newlen The number of bits this array should contain.

const const pure @property size_t dim();
Gets the length of a size_t array large enough to hold all stored bits.

Returns:
The size a size_t array would have to be to store this array.

const @property BitArray dup();
Duplicates this array, much like the dup property for built-in arrays.

Returns:
A duplicate of this array.

BitArray opSliceAssign(BitArray rhs);
Copy the bits from one array into this array. This is not a shallow copy.

Params:
BitArray rhs A BitArray with at least the same number of bits as this bit array.

Returns:
A shallow copy of this array.

BitArray ba = [0,1,0,1,0];
BitArray ba2;
ba2.length = ba.length;
ba2[] = ba; // perform the copy
ba[0] = true;
assert(ba2[0] == false);


void init(void[] target, size_t numbits);
Map BitArray onto target, with numbits being the number of bits in the array. Does not copy the data. This is the inverse of opCast.

Params:
void[] target The array to map.
size_t numbits The number of bits to map in target.

@property ref BitArray reverse();
Reverses the contents of this array in place, much like the reverse property for built-in arrays.

Returns:
A shallow copy of this array.

@property ref BitArray sort();
Sorts this array in place, with zero entries sorting before one. This is equivalent to the sort property for built-in arrays.

Returns:
A shallow copy of this array.

int opApply(scope int delegate(ref bool) dg);
int opApply(scope int delegate(ref size_t, ref bool) dg);
Operates on all bits in this array.

Params:
int delegate(ref bool) dg The supplied code as a delegate.

const const bool opEquals(ref const(BitArray) rhs);
Compares this array to another for equality. Two bit arrays are equal if they are the same size and contain the same series of bits.

Params:
const(BitArray) rhs The array to compare against.

Returns:
false if not equal and non-zero otherwise.

const int opCmp(ref const(BitArray) rhs);
Performs a lexicographical comparison of this array to the supplied array.

Params:
const(BitArray) rhs The array to compare against.

Returns:
A value less than zero if this array sorts before the supplied array, zero if the arrays are equavalent, and a value greater than zero if this array sorts after the supplied array.

const void[] opCast();
Convert this array to a void array.

Returns:
This array represented as a void array.

const bool opIndex(size_t pos);
Support for index operations, much like the behavior of built-in arrays.

Params:
size_t pos The desired index position.

In:
pos must be less than the length of this array.

Returns:
The value of the bit at pos.

BitArray opCom();
Generates a copy of this array with the unary complement operation applied.

Returns:
A new array which is the complement of this array.

const BitArray opAnd(ref const(BitArray) rhs);
Generates a new array which is the result of a bitwise and operation between this array and the supplied array.

Params:
const(BitArray) rhs The array with which to perform the bitwise and operation.

In:
rhs.length must equal the length of this array.

Returns:
A new array which is the result of a bitwise and with this array and the supplied array.

const BitArray opOr(ref const(BitArray) rhs);
Generates a new array which is the result of a bitwise or operation between this array and the supplied array.

Params:
const(BitArray) rhs The array with which to perform the bitwise or operation.

In:
rhs.length must equal the length of this array.

Returns:
A new array which is the result of a bitwise or with this array and the supplied array.

const BitArray opXor(ref const(BitArray) rhs);
Generates a new array which is the result of a bitwise xor operation between this array and the supplied array.

Params:
const(BitArray) rhs The array with which to perform the bitwise xor operation.

In:
rhs.length must equal the length of this array.

Returns:
A new array which is the result of a bitwise xor with this array and the supplied array.

const BitArray opSub(ref const(BitArray) rhs);
Generates a new array which is the result of this array minus the supplied array. a - b for BitArrays means the same thing as a & ~b.

Params:
const(BitArray) rhs The array with which to perform the subtraction operation.

In:
rhs.length must equal the length of this array.

Returns:
A new array which is the result of this array minus the supplied array.

const BitArray opCat(bool rhs);
const BitArray opCat_r(bool lhs);
const BitArray opCat(ref const(BitArray) rhs);
Generates a new array which is the result of this array concatenated with the supplied array.

Params:
bool rhs The array with which to perform the concatenation operation.

Returns:
A new array which is the result of this array concatenated with the supplied array.

pure bool opIndexAssign(bool b, size_t pos);
Support for index operations, much like the behavior of built-in arrays.

Params:
bool b The new bit value to set.
size_t pos The desired index position.

In:
pos must be less than the length of this array.

Returns:
The new value of the bit at pos.

BitArray opAndAssign(const(BitArray) rhs);
Updates the contents of this array with the result of a bitwise and operation between this array and the supplied array.

Params:
const(BitArray) rhs The array with which to perform the bitwise and operation.

In:
rhs.length must equal the length of this array.

Returns:
A shallow copy of this array.

BitArray opOrAssign(const(BitArray) rhs);
Updates the contents of this array with the result of a bitwise or operation between this array and the supplied array.

Params:
const(BitArray) rhs The array with which to perform the bitwise or operation.

In:
rhs.length must equal the length of this array.

Returns:
A shallow copy of this array.

BitArray opXorAssign(const(BitArray) rhs);
Updates the contents of this array with the result of a bitwise xor operation between this array and the supplied array.

Params:
const(BitArray) rhs The array with which to perform the bitwise xor operation.

In:
rhs.length must equal the length of this array.

Returns:
A shallow copy of this array.

BitArray opSubAssign(const(BitArray) rhs);
Updates the contents of this array with the result of this array minus the supplied array. a - b for BitArrays means the same thing as a & ~b.

Params:
const(BitArray) rhs The array with which to perform the subtraction operation.

In:
rhs.length must equal the length of this array.

Returns:
A shallow copy of this array.

BitArray opCatAssign(bool b);
BitArray opCatAssign(const(BitArray) rhs);
Updates the contents of this array with the result of this array concatenated with the supplied array.

Params:
rhs The array with which to perform the concatenation operation.

Returns:
A shallow copy of this array.


Page generated by Ddoc. Copyright (%C) 2005-2006 Digital Mars, www.digitalmars.com. All rights reserved.