BitArray

BitArray

A BitSet implementation with no limit due to bits being stored in an array. Also known as bit set, bit map or bit vector. This implementation will never throw out of bounds errors.

Constructor

new BitArray(minLengthopt)

Source:
Implements:
Parameters:
Name Type Attributes Default Description
minLength Number <optional>
1 The minimum length of the bitArray.
Throws:
In case 'minLength' is equals to or smaller than zero.
Type
Error

Members

(readonly) length :Number

Source:
Implements:
The index of the highest set bit plus one or the minimum set length, whichever is higher.
Type:
  • Number

Methods

(static) deserialize(input) → {BitArray}

Source:
Deserializes a string and returns a new instance.
Parameters:
Name Type Description
input String
Throws:
In case input could not be parsed.
Type
Error
Returns:
A new instance.
Type
BitArray

(static) fromArray(array) → {BitArray}

Source:
Produces a new BitArray instance from a value. The value may contain anything, the resulting bitArray is based on the truthiness of the value contents. Example: [true, 0, {}] will yield 101.
Parameters:
Name Type Description
array Array.<*>
Returns:
A new BitArray instance.
Type
BitArray

clone() → {BitSet}

Source:
Implements:
Produces a new bitset instance equal to this.
Returns:
Type
BitSet

copy(bitset) → {this}

Source:
Implements:
Copies a bitsetlike value or instance. Minimum length is preserved.
Parameters:
Name Type Description
bitset BitSetLike
Returns:
This instance.
Type
this

count() → {Number}

Source:
Implements:
Gets the number of set bits (1's) in this bitset. For the total number of bits, see BitSet#length.
Returns:
Type
Number

equals(other) → {Boolean}

Source:
Implements:
Checks whether this bitset is equal to another bitsetlike value or instance. They are equal if if their set bits match up.
Parameters:
Name Type Description
other BitSetLike
Returns:
Type
Boolean

flip(…masks) → {this}

Source:
Implements:
Flips bits based on one or more masks. Equivalent to a bitwise XOR operation. Only set bits in any of the provided bitmasks are affected.
Parameters:
Name Type Attributes Description
masks BitMask <repeatable>
Returns:
This instance.
Type
this

flipAll() → {this}

Source:
Implements:
Flips all bits in this bitset.
Returns:
This instance.
Type
this

flipAt(index) → {this}

Source:
Implements:
Flips a bit at a specific index.
Parameters:
Name Type Description
index Number Starting at 0, from the rightmost bit.
Throws:
In case 'index' is not an integer or out of bounds.
Type
Error
Returns:
This instance.
Type
this

flipRange(from, to) → {this}

Source:
Implements:
Flips all bits within a specific range.
Parameters:
Name Type Description
from Number Starting index, from the rightmost bit.
to Number The exclusive ending index.
Returns:
This instance.
Type
this

get(index) → {Boolean}

Source:
Implements:
Gets the bit at a specific index. Example: 001 at index 0 yields 1.
Parameters:
Name Type Description
index Number
Returns:
Type
Boolean

getRange(from, to) → {BitSet}

Source:
Implements:
Gets the bits within a specific index range. Example: 011 from 0 to 2 yields 11.
Parameters:
Name Type Description
from Number The inclusive lower bounds of the range.
to Number The exclusive upper bounds of the range.
Returns:
The Resulting BitSet.
Type
BitSet

intersect(…masks) → {this}

Source:
Implements:
Intersects this bitset with one or more bitmasks, only affecting this instance. Equivalent to a bitwise AND operation.
Parameters:
Name Type Attributes Description
masks BitMask <repeatable>
Returns:
This instance.
Type
this

intersects(…masks) → {Boolean}

Source:
Implements:
Checks whether this bitset intersects with one or more bitmasks. They intersect if any set bits in this bitset are also set in any of the provided bitmasks.
Parameters:
Name Type Attributes Description
masks BitMask <repeatable>
Returns:
Type
Boolean

off(…masks) → {this}

Source:
Implements:
Sets bits to 0 based on one or more masks. Equivalent to a bitwise AND NOT operation. Only set bits in any of the provided bitmasks are affected.
Parameters:
Name Type Attributes Description
masks BitMask <repeatable>
Returns:
This instance.
Type
this

on(…masks) → {this}

Source:
Implements:
Sets bits to 1 based on one or more masks. Equivalent to a bitwise OR operation. Only set bits in any of the provided bitmasks are affected.
Parameters:
Name Type Attributes Description
masks BitMask <repeatable>
Returns:
This instance.
Type
this

serialize() → {String}

Source:
Implements:
Serializes this bitset.
Returns:
Type
String

set(value, …masks) → {this}

Source:
Implements:
Sets bits to a specific value based on one or more masks. Only set bits in any of the provided bitmasks are affected.
Parameters:
Name Type Attributes Description
value Bit
masks BitMask <repeatable>
Returns:
This instance.
Type
this

setAll(value) → {this}

Source:
Implements:
Sets all bits in this bitset to a specific value.
Parameters:
Name Type Description
value Bit
Returns:
This instance.
Type
this

setAt(value, index) → {this}

Source:
Implements:
Sets a bit at a specific index to a specific value.
Parameters:
Name Type Description
value Bit
index Number Starting at 0, from the rightmost bit.
Throws:
In case 'index' is not an integer or out of bounds.
Type
Error
Returns:
This instance.
Type
this

setRange(value, from, to) → {this}

Source:
Implements:
Sets all bits within a specific range to a specific value.
Parameters:
Name Type Description
value Bit value
from Number Starting index, from the rightmost bit.
to Number The exclusive ending index.
Returns:
This instance.
Type
this

test(…masks) → {Boolean}

Source:
Implements:
Tests whether all bits are set based on one or more bitmasks. Only set bits in any of the provided bitmasks are tested.
Parameters:
Name Type Attributes Description
masks BitMask <repeatable>
Returns:
Type
Boolean

testAll(value) → {Boolean}

Source:
Implements:
Tests whether all bits in this bitset has one specific value.
Parameters:
Name Type Description
value Bit
Returns:
Type
Boolean

testAny(…masks) → {Boolean}

Source:
Implements:
Tests whether any bits are set based on one or more bitmasks. Only set bits in any of the provided bitmasks are tested.
Parameters:
Name Type Attributes Description
masks BitMask <repeatable>
Returns:
Type
Boolean

testAt(value, index) → {Boolean}

Source:
Implements:
Tests whether a bit at a specific index is equal to a specific value.
Parameters:
Name Type Description
value Bit
index Number Starting at 0, from the rightmost bit.
Throws:
In case 'index' is not an integer or out of bounds.
Type
Error
Returns:
Type
Boolean

toArray() → {Array.<Boolean>}

Source:
Implements:
Gets an array containing all the bits in this bitset.
Returns:
Type
Array.<Boolean>

toString() → {String}

Source:
Implements:
Gets a string representation of this bitset.
Returns:
Type
String

valueOf() → {Number}

Source:
Implements:
Gets the integer value of this instance.
Throws:
In case this instance cannot be represented by an integer (by exceeding 31 bits).
Type
Error
Returns:
Type
Number