An array data structure that compactly stores individual bits (boolean values)

Example:

var o = new de.polygonal.ds.BitVector(40);
for (i in 0...40) {
    if (i & 1 == 0) {
        o.set(i);
    }
}
trace(o); //outputs:

[ BitVector numBits=40
  0 -> 01010101010101010101010101010101
  1 -> 00000000000000000000000001010101
]

Constructor

new (numBits:Int)

Creates a bit-vector capable of storing a total of numBits bits.

Variables

read onlyarrSize:Int

The total number of 32-bit integers allocated for storing the bits.

read onlykey:Int

A unique identifier for this object.

A hash table transforms this key into an index of an array element by using a hash function.

read onlynumBits:Int

The total number of bits that the bit-vector can store.

Methods

inline clear (i:Int):Void

Sets the bit at index i to zero.

inline clearAll ():BitVector

Sets all bits in the bit-vector to zero.

clearRange (min:Int, max:Int):BitVector

Clears all bits in the range [min, max).

This is faster than clearing individual bits by using this.clear().

clone ():BitVector

Creates a copy of this bit vector.

free ():Void

Destroys this object by explicitly nullifying the array storing the bits.

inline getBucketAt (i:Int):Int

Returns the bucket at index i.

A bucket is a 32-bit integer for storing bit flags.

inline getBuckets (out:Array<Int>):Int

Writes all buckets to out.

A bucket is a 32-bit integer for storing bit flags.

Returns:

the total number of buckets.

inline has (i:Int):Bool

Returns true if the bit at index i is 1.

inline ofBool (i:Int, cond:Bool):BitVector

Sets the bit at index i to one if cond is true or clears the bit at index i if cond is false.

ofBytes (bytes:BytesData, ?bigEndian:Bool):Void

Copies the bits from bytes into this bit vector.

The bit-vector is resized to the size of bytes.

Parameters:

bigEndian

the input byte order (default is little endian)

ones ():Int

The total number of bits set to one.

resize (numBits:Int):BitVector

Resizes the bit-vector to numBits bits.

Preserves existing values if new size > old size.

inline set (i:Int):BitVector

Sets the bit at index i to one.

inline setAll ():BitVector

Sets all bits in the bit-vector to one.

setRange (min:Int, max:Int):BitVector

Sets all bits in the range [min, max).

This is faster than setting individual bits by using this.set().

toBytes (?bigEndian:Bool):BytesData

Writes the data in this bit-vector to a byte array.

The number of bytes equals this.bucketSize() × 4 and the number of bits equals numBits.

Parameters:

bigEndian

the byte order (default is little endian)

toString ():String

Prints out all elements.