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

Methods


Constructor

.constructor<T>() ⇒ BitSet<T>

Template ParamType Definition
Textends number

Methods

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

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<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).

ParamTypeDescription
bitsT[]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.

ParamTypeDescription
bitTThe bit to check.