Constructor
new BitField(minLengthopt)
- Source:
- Implements:
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
minLength |
Number |
<optional> |
1
|
The minimum length of the bitfield. |
Throws:
-
-
In case length exceeds 31 (consider using BitArray instead if u may reach this limit).
- Type
- Error
-
-
-
In case 'minLength' is equals to or smaller than zero.
- Type
- Error
-
Members
(readonly) length :Number
- Description:
- The index of the highest set bit plus one or the minimum set length, whichever is higher.
- Source:
- Implements:
The index of the highest set bit plus one or the minimum set length, whichever is higher.
Type:
- Number
Methods
clone() → {BitSet}
- Description:
- Produces a new bitset instance equal to this.
- Source:
- Implements:
Returns:
- Type
- BitSet
copy(bitset) → {this}
- Description:
- Copies a bitsetlike value or instance. Minimum length is preserved.
- Source:
- Implements:
Parameters:
Name | Type | Description |
---|---|---|
bitset |
BitSetLike |
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:
- Implements:
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:
- Implements:
Parameters:
Name | Type | Description |
---|---|---|
other |
BitSetLike |
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:
- Implements:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
masks |
BitMask |
<repeatable> |
Returns:
This instance.
- Type
- this
flipAll() → {this}
- Description:
- Flips all bits in this bitset.
- Source:
- Implements:
Returns:
This instance.
- Type
- this
flipAt(index) → {this}
- Description:
- Flips a bit at a specific index.
- Source:
- Implements:
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:
- Implements:
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:
- Implements:
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:
- Implements:
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:
- Implements:
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:
- Implements:
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:
- Implements:
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:
- Implements:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
masks |
BitMask |
<repeatable> |
Returns:
This instance.
- Type
- this
serialize() → {String}
- Description:
- Serializes this bitset.
- Source:
- Implements:
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:
- Implements:
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:
- Implements:
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:
- Implements:
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:
- Implements:
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:
- Implements:
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:
- Implements:
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:
- Implements:
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:
- Implements:
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:
- Implements:
Returns:
- Type
- Array.<Boolean>
toString() → {String}
- Description:
- Gets a string representation of this bitset.
- Source:
- Implements:
Returns:
- Type
- String
valueOf() → {Number}
- Description:
- Gets the integer value of this bitset.
- Source:
- Implements:
Returns:
- Type
- Number
(static) deserialize(input) → {BitField}
- Description:
- Deserializes a string and returns a new instance.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
input |
String |
Throws:
-
In case input could not be parsed.
- Type
- Error
Returns:
A new instance.
- Type
- BitField
(static) fromArray(array) → {BitField}
- Description:
- Produces a new BitField instance from an array. The value may contain anything, the resulting bitfield is based on the truthiness of the value contents. Example: [true, 0, {}] will yield 101.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
array |
Array.<*> |
Throws:
-
In case length exceeds 31 (consider using BitArray instead if u may reach this limit).
- Type
- Error
Returns:
A new BitField instance.
- Type
- BitField