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
Variables
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.
Methods
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()
.
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.
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.
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) |
---|
resize (numBits:Int):BitVector
Resizes the bit-vector to numBits
bits.
Preserves existing values if new size > old size.
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 = 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) |
---|