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

Example:

var o = new 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

@:value(0)read onlyarrSize:Int = 0

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

@:value(HashKey.next())read onlykey:Int = HashKey.next()

A unique identifier for this object.

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

@:value(0)read onlynumBits:Int = 0

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

Methods

inlineclear (i:Int):Void

Sets the bit at index i to zero.

inlineclearAll ():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.

inlinegetBucketAt (i:Int):Int

Returns the bucket at index i.

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

inlinegetBuckets (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.

inlinehas (i:Int):Bool

Returns true if the bit at index i is 1.

inlineofBool (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.

@:value({ bigEndian : false })ofBytes (bytes:BytesData, bigEndian:Bool = false):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.

inlineset (i:Int):BitVector

Sets the bit at index i to one.

inlinesetAll ():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().

@:value({ bigEndian : false })toBytes (bigEndian:Bool = false):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.