BitSet
Stores a bit pattern to quickly test if an index is enabled / disabled.
This class can store up to 32 different values in the range [0; 31].
Usage
const bitset = new BitSet();
bitset.enable(10); // Enable bit at index `10`.
console.log(bitset.enabled(10)); // Prints 'true'.
TypeScript
The set can be typed over an enum:
enum Tag {
First = 0,
Second = 1,
}
const bitset = new BitSet<Tag>();
bitset.enable(Tag.First);
Static Members
- .constructor<T>() ⇒ BitSet<T>
Methods
- .disable(…bits) ⇒ BitSet<T>
- .disableAll() ⇒ BitSet<T>
- .enable(…bits) ⇒ BitSet<T>
- .enableAll() ⇒ BitSet<T>
- .enabled(bit) ⇒ boolean
Constructor
.constructor<T>() ⇒ BitSet<T>
| Template Param | Type Definition |
|---|---|
T | extends number |
Methods
.disable(…bits: T[][]) ⇒ BitSet<T>
Disable the bit at the given index.
Returns: Reference to self (for method chaining).
| Param | Type | Description |
|---|---|---|
bits | T[] | A spread of all the bits to disable. |
.disableAll() ⇒ BitSet<T>
Disable all bits.
Returns: Reference to self (for method chaining).
.enable(…bits: T[][]) ⇒ BitSet<T>
Enable the bit at the given index.
Returns: Reference to self (for method chaining).
| Param | Type | Description |
|---|---|---|
bits | T[] | A spread of all the bits to enable. |
.enableAll() ⇒ BitSet<T>
Enable all bits.
Returns: Reference to self (for method chaining).
.enabled(bit: T) ⇒ boolean
Checker whether the bit is set or not.
Returns: true if it’s enabled, false otherwise.
| Param | Type | Description |
|---|---|---|
bit | T | The bit to check. |