UNPKG

2.29 kBTypeScriptView Raw
1interface BitFieldOptions {
2 /**
3 * If you `set` an index that is out-of-bounds, the bitfield
4 * will automatically grow so that the bitfield is big enough
5 * to contain the given index, up to the given size (in bit).
6 *
7 * If you want the Bitfield to grow indefinitely, pass `Infinity`.
8 *
9 * @default 0.
10 */
11 grow?: number;
12}
13export default class BitField {
14 /**
15 * Grow the bitfield up to this number of entries.
16 * @default 0.
17 */
18 private readonly grow;
19 /** The internal storage of the bitfield. */
20 buffer: Uint8Array;
21 /** The number of bits in the bitfield. */
22 get length(): number;
23 /**
24 * Constructs a BitField.
25 *
26 * @param data Either a number representing the maximum number of supported bits, or a Uint8Array.
27 * @param opts Options for the bitfield.
28 */
29 constructor(data?: number | Uint8Array, options?: BitFieldOptions);
30 /**
31 * Get a particular bit.
32 *
33 * @param bitIndex Bit index to retrieve.
34 * @returns A boolean indicating whether the `i`th bit is set.
35 */
36 get(bitIndex: number): boolean;
37 /**
38 * Set a particular bit.
39 *
40 * Will grow the underlying array if the bit is out of bounds and the `grow` option is set.
41 *
42 * @param bitIndex Bit index to set.
43 * @param value Value to set the bit to. Defaults to `true`.
44 */
45 set(bitIndex: number, value?: boolean): void;
46 /**
47 * Sets a value or an array of values.
48 *
49 * @param array An array of booleans to set.
50 * @param offset The bit offset at which the values are to be written.
51 */
52 setAll(array: ArrayLike<boolean>, offset?: number): void;
53 /**
54 * Loop through the bits in the bitfield.
55 *
56 * @param callbackfn Function to be called with the bit value and index.
57 * @param start Index of the first bit to look at.
58 * @param end Index of the first bit that should no longer be considered.
59 */
60 forEach(callbackfn: (bit: boolean, index: number) => void, start?: number, end?: number): void;
61 /**
62 * Check if all bits in the Bitfield are unset.
63 *
64 * @returns A boolean indicating whether all bits are unset.
65 */
66 isEmpty(): boolean;
67}
68export {};
69//# sourceMappingURL=index.d.ts.map
\No newline at end of file