- Description:
- A data structure that holds a sequence of bits and contains convenient methods for common bitwise operations.
- Source:
A data structure that holds a sequence of bits and contains convenient methods for common bitwise operations.
Members
(readonly) length :Number
- Description:
- The index of the highest set bit plus one or the minimum set length, whichever is higher.
- Source:
The index of the highest set bit plus one or the minimum set length, whichever is higher.
Type:
Methods
- Description:
- Produces a new bitset instance equal to this.
- Source:
Returns:
-
Type
-
BitSet
copy(bitset) → {this}
- Description:
- Copies a bitsetlike value or instance. Minimum length is preserved.
- Source:
Parameters:
Returns:
This instance.
-
Type
-
this
count() → {Number}
- Description:
- Gets the number of set bits (1's) in this bitset.
For the total number of bits, see BitSet#length.
- Source:
Returns:
-
Type
-
Number
equals(other) → {Boolean}
- Description:
- Checks whether this bitset is equal to another bitsetlike value or instance. They are equal if
if their set bits match up.
- Source:
Parameters:
Returns:
-
Type
-
Boolean
flip(…masks) → {this}
- Description:
- 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.
- Source:
Parameters:
Name |
Type |
Attributes |
Description |
masks |
BitMask
|
<repeatable>
|
|
Returns:
This instance.
-
Type
-
this
flipAll() → {this}
- Description:
- Flips all bits in this bitset.
- Source:
Returns:
This instance.
-
Type
-
this
flipAt(index) → {this}
- Description:
- Flips a bit at a specific index.
- Source:
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}
- Description:
- Flips all bits within a specific range.
- Source:
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}
- Description:
- Gets the bit at a specific index.
Example: 001 at index 0 yields 1.
- Source:
Parameters:
Name |
Type |
Description |
index |
Number
|
|
Returns:
-
Type
-
Boolean
getRange(from, to) → {BitSet}
- Description:
- Gets the bits within a specific index range.
Example: 011 from 0 to 2 yields 11.
- Source:
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}
- Description:
- Intersects this bitset with one or more bitmasks, only affecting this instance.
Equivalent to a bitwise AND operation.
- Source:
Parameters:
Name |
Type |
Attributes |
Description |
masks |
BitMask
|
<repeatable>
|
|
Returns:
This instance.
-
Type
-
this
intersects(…masks) → {Boolean}
- Description:
- 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.
- Source:
Parameters:
Name |
Type |
Attributes |
Description |
masks |
BitMask
|
<repeatable>
|
|
Returns:
-
Type
-
Boolean
off(…masks) → {this}
- Description:
- 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.
- Source:
Parameters:
Name |
Type |
Attributes |
Description |
masks |
BitMask
|
<repeatable>
|
|
Returns:
This instance.
-
Type
-
this
on(…masks) → {this}
- Description:
- 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.
- Source:
Parameters:
Name |
Type |
Attributes |
Description |
masks |
BitMask
|
<repeatable>
|
|
Returns:
This instance.
-
Type
-
this
serialize() → {String}
- Description:
- Source:
Returns:
-
Type
-
String
set(value, …masks) → {this}
- Description:
- Sets bits to a specific value based on one or more masks.
Only set bits in any of the provided bitmasks are affected.
- Source:
Parameters:
Name |
Type |
Attributes |
Description |
value |
Bit
|
|
|
masks |
BitMask
|
<repeatable>
|
|
Returns:
This instance.
-
Type
-
this
setAll(value) → {this}
- Description:
- Sets all bits in this bitset to a specific value.
- Source:
Parameters:
Name |
Type |
Description |
value |
Bit
|
|
Returns:
This instance.
-
Type
-
this
setAt(value, index) → {this}
- Description:
- Sets a bit at a specific index to a specific value.
- Source:
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}
- Description:
- Sets all bits within a specific range to a specific value.
- Source:
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}
- Description:
- Tests whether all bits are set based on one or more bitmasks.
Only set bits in any of the provided bitmasks are tested.
- Source:
Parameters:
Name |
Type |
Attributes |
Description |
masks |
BitMask
|
<repeatable>
|
|
Returns:
-
Type
-
Boolean
testAll(value) → {Boolean}
- Description:
- Tests whether all bits in this bitset has one specific value.
- Source:
Parameters:
Name |
Type |
Description |
value |
Bit
|
|
Returns:
-
Type
-
Boolean
testAny(…masks) → {Boolean}
- Description:
- Tests whether any bits are set based on one or more bitmasks.
Only set bits in any of the provided bitmasks are tested.
- Source:
Parameters:
Name |
Type |
Attributes |
Description |
masks |
BitMask
|
<repeatable>
|
|
Returns:
-
Type
-
Boolean
testAt(value, index) → {Boolean}
- Description:
- Tests whether a bit at a specific index is equal to a specific value.
- Source:
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>}
- Description:
- Gets an array containing all the bits in this bitset.
- Source:
Returns:
-
Type
-
Array.<Boolean>
toString() → {String}
- Description:
- Gets a string representation of this bitset.
- Source:
Returns:
-
Type
-
String
valueOf() → {Number}
- Description:
- Gets the integer value of this bitset.
- Source:
Returns:
-
Type
-
Number