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 

1const bitset = new BitSet();
2bitset.enable(10); // Enable bit at index `10`.
3console.log(bitset.enabled(10)); // Prints 'true'.

TypeScript 

The set can be typed over an enum:

1enum Tag {
2    First = 0,
3    Second = 1,
4}
5
6const bitset = new BitSet<Tag>();
7bitset.enable(Tag.First);

.constructor<T>() ⇒ BitSet 

Template ParamType Definition
Textends number

.disable(…bits: T[][]) ⇒ BitSet 

Disable the bit at the given index.

Returns: Reference to self (for method chaining).

ParamTypeDescription
bitsT[]A spread of all the bits to disable.

.disableAll() ⇒ BitSet 

Disable all bits.

Returns: Reference to self (for method chaining).

.enable(…bits: T[][]) ⇒ BitSet 

Enable the bit at the given index.

Returns: Reference to self (for method chaining).

ParamTypeDescription
bitsT[]A spread of all the bits to enable.

.enableAll() ⇒ BitSet 

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.

ParamTypeDescription
bitTThe bit to check.