This module contains a packed bit array implementation in the style of D's
built-in dynamic arrays.
License:
BSD style: see license.txt
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.
- static BitArray
opCall
(bool[] bits);
- This initializes a BitArray of bits.length bits, where each bit value
matches the corresponding boolean value in bits.
Params:
| bool[] bits |
The initialization value. |
Returns:
A BitArray with the same number and sequence of elements as bits.
- uint
length
();
- Get the number of bits in this array.
Returns:
The number of bits in this array.
- void
length
(uint newlen);
- Resizes this array to newlen bits. If newlen is larger than the current
length
, the new bits will be initialized to zero.
Params:
| uint newlen |
The number of bits this array should contain. |
- uint
dim
();
- Gets the length of a uint array large enough to hold all stored bits.
Returns:
The size a uint array would have to be to store this array.
- BitArray
dup
();
- Duplicates this array, much like the
dup
property for built-in arrays.
Returns:
A duplicate of this array.
- void
opAssign
(bool[] bits);
- Resets the length of this array to bits.length and then initializes this
Resizes this array to hold bits.length bits and initializes each bit
value to match the corresponding boolean value in bits.
Params:
| bool[] bits |
The initialization value. |
- void
init
(void[] target, uint 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. |
| uint numbits |
The number of bits to map in target. |
- 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.
- 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
(int delegate(ref bool) dg);
int
opApply
(int delegate(ref uint, ref bool) dg);
- Operates on all bits in this array.
Params:
| int delegate(ref bool) dg |
The supplied code as a delegate. |
- int
opEquals
(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:
| BitArray rhs |
The array to compare against. |
Returns:
zero if not equal and non-zero otherwise.
- int
opCmp
(BitArray rhs);
- Performs a lexicographical comparison of this array to the supplied
array.
Params:
| 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.
- void[]
opCast
();
- Convert this array to a void array.
Returns:
This array represented as a void array.
- bool
opIndex
(uint pos);
- Support for index operations, much like the behavior of built-in arrays.
Params:
| uint 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.
- BitArray
opAnd
(BitArray rhs);
- Generates a new array which is the result of a bitwise and operation
between this array and the supplied array.
Params:
| 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.
- BitArray
opOr
(BitArray rhs);
- Generates a new array which is the result of a bitwise or operation
between this array and the supplied array.
Params:
| 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.
- BitArray
opXor
(BitArray rhs);
- Generates a new array which is the result of a bitwise xor operation
between this array and the supplied array.
Params:
| 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.
- BitArray
opSub
(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:
| 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.
- BitArray
opCat
(bool rhs);
BitArray
opCat_r
(bool lhs);
BitArray
opCat
(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.
- bool
opIndexAssign
(bool b, uint pos);
- Support for index operations, much like the behavior of built-in arrays.
Params:
| bool b |
The new bit value to set. |
| uint 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
(BitArray rhs);
- Updates the contents of this array with the result of a bitwise and
operation between this array and the supplied array.
Params:
| 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
(BitArray rhs);
- Updates the contents of this array with the result of a bitwise or
operation between this array and the supplied array.
Params:
| 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
(BitArray rhs);
- Updates the contents of this array with the result of a bitwise xor
operation between this array and the supplied array.
Params:
| 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
(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:
| 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
(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.
|