BitSet

BitSet

Source:
A data structure that holds a sequence of bits and contains convenient methods for common bitwise operations.

Members

(readonly) length :Number

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

Methods

clone() → {BitSet}

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

copy(bitset) → {this}

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

count() → {Number}

Source:
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:
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:
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:
Flips all bits in this bitset.
Returns:
This instance.
Type
this

flipAt(index) → {this}

Source:
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:
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:
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:
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:
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:
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:
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:
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:
Serializes this bitset.
Returns:
Type
String

set(value, …masks) → {this}

Source:
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:
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:
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:
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:
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:
Tests whether all bits in this bitset has one specific value.
Parameters:
Name Type Description
value Bit
Returns:
Type
Boolean

testAny(…masks) → {Boolean}

Source:
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:
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:
Gets an array containing all the bits in this bitset.
Returns:
Type
Array.<Boolean>

toString() → {String}

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

valueOf() → {Number}

Source:
Gets the integer value of this bitset.
Returns:
Type
Number